'Kafka simple producer not sending messages and not giving an error

I am writing a simple producer i just want to send raw data into a topic. for some reason i need to specify serialiser that will convert the message to json then to utf-8 then send in a json message..

this code doesn't work (no error but nothing to consume in the topic)

from kafka import KafkaProducer

producer = KafkaProducer(bootstrap_servers=['localhost:9092'])
topic = "my_new_topic5"

producer.send(topic, b'test message')

this code works

producer = KafkaProducer(bootstrap_servers=['localhost:9092'],
                     value_serializer=lambda x:
                     dumps(x).encode('utf-8'))

for e in range(2):
    data = {'number': e}
    producer.send('numtest', value=data)
    sleep(5)


Solution 1:[1]

if you using windows machine then there is a problem to follow quickstart,I did struggle 2 days solution: you need to set kafka_home and all the command you need to run under the window directory

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 katyRosale