我正在尝试使用stomp.py从 activemq 获取消息,然后对其进行一些处理。但是在某些情况下,某些消息的处理失败并且该消息丢失了。
在消息完全处理之前,如何防止删除消息?
例如,在我的代码中,当队列中有新条目时,将调用on_message函数并开始处理,但如果在中间被中断,则消息丢失。我该如何阻止它?
这是我的代码:
conn = stomp.Connection([(host, 61613)])
conn.set_listener('ML', MyListener())
conn.start()
conn.connect('admin', 'admin', wait=True)
conn.subscribe(destination=/queue/someque, id=1, ack='auto')
print "running"
while 1:
print 'waiting'
time.sleep(2.5)
这是我的监听器类:
class MyListener(stomp.ConnectionListener):
def on_message(self, headers, message):
print headers
print message
do_something()
提前致谢。