0

我的应用程序中有两个 python 脚本 producer.py 和 consumer.py。

# producer.py
client = pulsar.Client("pulsar://localhost:6650")
producer = client.create_producer("topic1")
producer.send(pickle.dumps(obj))

producer = client.create_producer("topic2")
producer.send(pickle.dumps(obj))

# consumer.py
client = pulsar.Client("pulsar://localhost:6650")
consumer = client.subscribe("topic1", "sub1")
msg = consumer.receive()
consumer.acknowledge(msg)
data = msg.data()

consumer = client.subscribe("topic2", "sub2")
msg = consumer.receive()
consumer.acknowledge(msg)
data = msg.data()

producer.py 生成两个主题,consumer.py 订阅两个主题(主题名称每次运行都会更改)。刚开始启动 producer.py 时,消费者收不到任何东西,进程处于阻塞状态。先启动consumer.py,再启动producer.py,consumer可以接收到第一个topic的数据,但是还是不能接收到第二个topic。

4

0 回答 0