code: def producer_demo():
      producer = KafkaProducer(
          bootstrap_servers=["localhost:9092"],
          key_serializer=lambda k: json.dumps(k).encode(),
          value_serializer=lambda v: json.dumps(v).encode(),
      )
      # send three example messages
      # a topic that doesn't exist will be created
      for i in range(0, 3):
          future = producer.send(
              "serving_stream",
              key="test",  # same key will be sent to same partition
              value=str(i),
              partition=0,
          )  # send to partition 0
          print("send {}".format(str(i)))
          try:
              future.get(timeout=10)  # check if send successfully
          except kafka_errors:  # throw kafka_errors if failed
              traceback.format_exc()
      producer.close()
  
imports: from kafka import KafkaProducer, KafkaConsumer
  from kafka.errors import kafka_errors
  import traceback
  import json
  import sys
label_desc: Use image node_id 1 for calling a global function with example usage: producer_demo() without return types