I am trying to load a simple text file instead of standard input in Kafka. After downloading Kafka, I performed the following steps:
Started zookeeper:
You can pipe it in:
kafka-console-producer.sh --broker-list localhost:9092 --topic my_topic
--new-producer < my_file.txt
Found here.
From 0.9.0:
kafka-console-producer.sh --broker-list localhost:9092 --topic my_topic < my_file.txt
echo "Hello" | kafka-console-producer.sh --broker-list localhost:9092 --topic my_topic
Here are few ways which are little more generalised but may be overkill for simple file
tail
tail -n0 -F my_file.txt | kafka-console-producer.sh --broker-list localhost:9092 --topic my_topic
Explanation
tail reads from the end of the file as it grows or logs are being added to it continuously-n0 indicates outputlast 0 lines so only new line is selected-F follows the file by name instead the descriptor, hence it works even if it is rotatedsyslog-ng
options {                                                                                                                             
    flush_lines (0);                                                                                                                
    time_reopen (10);                                                                                                               
    log_fifo_size (1000);                                                                                                          
    long_hostnames (off);                                                                                                           
    use_dns (no);                                                                                                                   
    use_fqdn (no);                                                                                                                  
    create_dirs (no);                                                                                                               
    keep_hostname (no);                                                                                                             
};
source s_file {
    file("path to my-file.txt" flags(no-parse));
}
destination loghost {
    tcp("*.*.*.*" port(5140));
} 
consuming
nc -k -l 5140 | kafka-console-producer.sh --broker-list localhost:9092 --topic my_topic
Explanation(from man nc)
-k' Forces nc to stay listening for another connection after its current connection is completed. It is an error to use this option without the -l option.
-l' Used to specify that nc should listen for an incoming connection rather than initiate a connection to a remote host. It is an error to use this option in conjunction with the -p, -s, or -z options. Additionally, any timeouts specified with the -w option are ignored.
Ref
Syslog-ng
$ kafka-console-producer.sh --broker-list localhost:9092 --topic my_topic < my_file.txt
worked for me in Kafka-0.9.0