I've got my zookeeper and broker running.
When I send a message from the command line like so:
from kafka import KafkaProducer
producer = KafkaProducer(bootstrap_servers='localhost:9092')
producer.send('topic', b'some_message_bytes')
I'm able to receive it on the other end in my consumer running this:
from kafka import KafkaConsumer
consumer = KafkaConsumer('topic')
for msg in consumer:
print msg
However, when I include the exact same code for the producer inside of a python script and run it, the consumer doesn't print the message and furthermore, it does not even get sent. I confirmed this by running this on my command line:
./bin/kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list
localhost:9092 --topic topic --time -1 --offsets 1 | awk -F ":" '{sum +=
$3} END {print sum}'
This shows the number of messages in the current topic. It goes up as I send more messages from the command line-version of the python producer, but the number of messages in the topic does not get incremented after running the python script.
Does anyone know what's going on here?