• kafka_producer


    使用pykafka来进行消息生产

     1 #coding:utf8
     2 from pykafka import KafkaClient
     3 import json
     4 
     5 client = KafkaClient(hosts='192.168.1.1:9092')
     6 
     7 topic = client.topics['perfin']
     8 producer = topic.get_producer(use_rdkafka=False)
     9 producer.start()
    10 
    11 msg_dict = {
    12     "sleep_time": 10,
    13     "db_config" : {
    14       "database"  : "test",
    15       "host"      : "192.168.137.12",
    16       "user"      : "root",
    17       "password"  : "root"
    18     },
    19     "table"     : "msg",
    20     "msg"       : "Hello World"
    21   }
    22 msg = json.dumps(msg_dict)
    23 producer.produce(msg)
    24 producer.stop()
  • 相关阅读:
    将.lib库文件转换成.a库文件的工具
    协议
    协议
    bzoj1066
    bzoj2668
    bzoj2245
    bzoj2324后续思考
    bzoj2324
    jsoi2014前两轮回眸
    bzoj1293
  • 原文地址:https://www.cnblogs.com/yeyong/p/11854944.html
Copyright © 2020-2023  润新知