本文整理汇总了Python中kafka.producer.SimpleProducer.send_message方法的典型用法代码示例。如果您正苦于以下问题:Python SimpleProducer.send_message方法的具体用法?Python SimpleProducer.send_message怎么用?Python SimpleProducer.send_message使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kafka.producer.SimpleProducer
的用法示例。
在下文中一共展示了SimpleProducer.send_message方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: KafkaClient
# 需要导入模块: from kafka.producer import SimpleProducer [as 别名]
# 或者: from kafka.producer.SimpleProducer import send_message [as 别名]
client = KafkaClient("localhost:9092")
producer = SimpleProducer(client)
consumer = SimpleConsumer(client, "text-Tweets", "my-topic")
#this is Dillon Fancher's API key
api = twitter.Api(consumer_key='G1ztnAQmyriiOqcyt9pGQ', consumer_secret='TzNhT5oCWMMU5eIk6E61bgSuXQ7qDHuYv5EbYwDKQ', access_token_key='572163554-le5J2mX0lb5IMOdAVPyAkxQ8M24UIMIyQMafqyur', access_token_secret='EB9xZBqfRVuga9tUsrqiP5qf5PHCsvsGrm3UkHz3nyZPc', cache=None)
while(True):
statuses = api.GetStreamSample()
#Iterate through all geolocated tweets
for obj in statuses:
if 'text' in obj and 'coordinates' in obj and 'lang' in obj and 'place' in obj:
place = obj['place']
if place != None and 'country_code' in place:
if obj['text'] != None and obj['coordinates'] != None and obj['place']['country_code'] == "US" and obj['lang'] == "en":
# Grab the user who created the tweet
# print "Username: %s" % (obj['user']['name'])
# Record the tweet
#print "Tweet: %s\nLocation: (%f, %f)\n" % (obj['text'], obj['coordinates']['coordinates'][0], obj['coordinates']['coordinates'][1])
#db.TweetsGeo.update({'id' : obj['id']}, obj, True)
producer.send_message('my-topic', obj)
continue
for message in consumer:
print(message)
示例2: KafkaClient
# 需要导入模块: from kafka.producer import SimpleProducer [as 别名]
# 或者: from kafka.producer.SimpleProducer import send_message [as 别名]
strat.run()
stat = plt.plotjson()
print stat
return stat
if __name__ == '__main__':
if not os.environ.has_key('DOCKER_HOST'):
os.environ['DOCKER_HOST'] = "172.17.42.1"
print "%s:9092" % os.environ['DOCKER_HOST'].strip('\n')
client = KafkaClient("%s:9092" % os.environ['DOCKER_HOST'].strip('\n'))
producer = SimpleProducer(client, async=False, req_acks=SimpleProducer.ACK_AFTER_LOCAL_WRITE, ack_timeout=2000)
#向脚本传入参数
start = int(sys.argv[1])
end = int(sys.argv[2])
code = sys.argv[3]
sid = sys.argv[4]
args = {'start': start, 'end':end, 'code':code, "sid":sid}
Stat = algoparser(**args)
producer.send_message("plot", Stat)