我尝试多个消费者。
但它不起作用?
它是如何工作的?在
怎么了?在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}。。。。在
请帮帮我!我解决不了