0

There two python scripts producer.py and consumer.py in my application.

# 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()

The producer.py generates two topics, and the consumer.py subscribes two topics (The topic name is changed every run). When start producer.py at first, the consumer cannot receive anything, the process is blocking. When start consumer.py at first, then start producer.py, the consumer can receive the data of first topic, but the second topic is still cannot be received.

  • 2
    it seems like you have the code `cosumer = client.subscribe("topic1", "sub1")` repeated twice on your consumer. Maybe you need to try to subscribe to `"topic2"` on the second run? – jpnadas Jun 22 '20 at 10:28
  • Oh, sorry, it's a mistake, it is "topic2" in my application. – Huanran Xue Jun 22 '20 at 11:09

0 Answers0