kafka python消费者重复消费,如何在pythonkafka中使用多个消费者?

我尝试多个消费者。

但它不起作用?

它是如何工作的?在

怎么了?在consumer1 = KafkaConsumer(

bootstrap_servers=['localhost:9092'],

#auto_offset_reset='earliest' , # 'earliest',

#enable_auto_commit= False ,

group_id='sr',

value_deserializer=lambda x: loads(x.decode('utf-8')))

consumer1.subscribe("numtest")

consumer2 = KafkaConsumer(

bootstrap_servers=['localhost:9092'],

#auto_offset_reset='earliest' , # 'earliest',

#enable_auto_commit= False ,

group_id='sr',

value_deserializer=lambda x: loads(x.decode('utf-8')))

consumer2.subscribe("numtest")

producer = KafkaProducer(bootstrap_servers=['localhost:9092'],

key_serializer = None ,

value_serializer=lambda x:

dumps(x).encode('utf-8'))

def on_send_success(record_metadata):

print("topic : {} , partition : {} , offset : {}".\

format( record_metadata.topic , record_metadata.partition , record_metadata.offset))

for msg , message in zip(consumer1 , consumer2) :

print("="*50)

print ("topic=%s partition=%d offset=%d: key=%s value=%s" % (message.topic, message.partition,

message.offset, message.key,

message.value))

print ("topic=%s partition=%d offset=%d: key=%s value=%s" % (msg.topic, msg.partition,

msg.offset, msg.key,

msg.value))

key = str(message.offset) + " " + str(msg.offset)

producer.send('output', value= { key : key } ).add_callback(on_send_success)

print("="*50)

事实上,我想做的是我想让两台计算机为模型的表示做一个前输入,然后合并两个结果。在

相反,在合并时必须保持相同的偏移量。在

之后,我想发送结果输出主题。在

我在output主题中的预期结果如下:

{offset=1:offest=1},{offset=2:offest=2}。。。。在

请帮帮我!我解决不了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值