-
Notifications
You must be signed in to change notification settings - Fork 97
Description
Description of problem
We send messages from the client to the MQ server at a certain interval by using multiple threads following the steps below:
Producer
from rocketmq.client import Producer, Message
producer = Producer('PID-XXX')
producer.set_name_server_address('127.0.0.1:9876')
producer.start()
msg = Message('YOUR-TOPIC')
msg.set_keys('XXX')
msg.set_tags('XXX')
msg.set_body('XXXX')
ret = producer.send_sync(msg)
print(ret.status, ret.msg_id, ret.offset)
producer.shutdown()
When a restart of the MQ server including Namer Server Cluster and Broker Cluster causes the service to stop for a short time, the MQ client will report an error at first when sending a MQ message:
Throw an exception in the program as:
File "/usr/lib/python2.7/site-packages/neutron_lbaas/drivers/bcslb/monitor/eslb_monitor.py", line 80, in push_message_to_rocketMQ_handler
ret = producer.send_sync(msg)
File "/usr/lib64/python2.7/site-packages/rocketmq/client.py", line 210, in send_sync
ffi_check(dll.SendMessageSync(self._handle, msg, ctypes.pointer(c_result)))
File "/usr/lib64/python2.7/site-packages/rocketmq/exceptions.py", line 44, in ffi_check
raise exc_cls(msg)
ProducerSendSyncFailed: No route info of this topic: dawn-bcmq-performance-topic,error:-1,in file rocketmq-client-cpp/src/producer/DefaultMQProducerImpl.cpp line:418
We think the reason for this error is that the Name server cannot be connected normally, which leads to no routing information. However, when the MQ server returns to normal after restart, the client will still keep reporting errors:
ProducerStartFailed: The producer group[] has been created before, specify another name please.,error:-1,in file rocketmq-client-cpp/src/producer/DefaultMQProducerImpl.cpp line:79
Problem analysis
When the MQ Server is stopped, the first thread has been in an abnormal state and cannot go to the following shutdown step normally:
producer.shutdown()
Then, the program starts the second thread to send messages, and calling producer.start() results in an error:
The producer group[ ] has been created before, specify another name please.
As long as the first thread that has the problem at the beginning cannot shutdown producer normally, all subsequent new threads will cause the same error as the second thread when run to producer.start(). Even when the MQ server restarts and returns to normal, the client will continue to report that same error.
suggestion
- First suggestion
When the producer sends a message successfully, the program will return SendStatus.OK=0 to the ret variable. So we think when the producer fails to send a message, the program should return an error code to the ret accordingly and not to throw an exception to prevent the thread from running the rest of code, especially the following step:
producer.shutdown()
- Second suggestion
Is there recommended usage steps of producer for rocketmq's multi-thread usage scenarios?