当前位置: 首页>>代码示例>>Python>>正文


Python SimpleProducer.send_message方法代码示例

本文整理汇总了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)
开发者ID:CUBigDataClass,项目名称:Twitter-EmotiMap,代码行数:31,代码来源:EC2Firehose.py

示例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)





开发者ID:StratsOn,项目名称:pyalgotrade,代码行数:27,代码来源:engine.py


注:本文中的kafka.producer.SimpleProducer.send_message方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。