apache / rocketmq-client-python

Apache RocketMQ python client
https://rocketmq.apache.org/
Apache License 2.0
271 stars 95 forks source link

readme example consumer.shutdown() is unreachable #127

Closed shane965 closed 1 year ago

shane965 commented 2 years ago

BUG REPORT

consumer.shutdown() is unreachable :

import time

from rocketmq.client import PushConsumer, ConsumeStatus

def callback(msg):
    print(msg.id, msg.body)
    return ConsumeStatus.CONSUME_SUCCESS

consumer = PushConsumer('CID_XXX')
consumer.set_name_server_address('127.0.0.1:9876')
consumer.subscribe('YOUR-TOPIC', callback)
consumer.start()

while True:
    time.sleep(3600)

consumer.shutdown() # <- This code is unreachable

maybe can be changed to

try:
    while True:
        time.sleep(3600)
except KeyboardInterrupt:
    consumer.shutdown()
miner-k commented 1 year ago

you should create a class, consumer.shutdown() as new function of the class

shane965 commented 1 year ago

you should create a class, consumer.shutdown() as new function of the class

Thank you for your reply. I will try it when I have time.