0

我正在尝试使用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()

提前致谢。

4

1 回答 1

1

问题似乎是您正在使用“自动”确认模式,因此消息将在代理传递给客户端之前得到确认,这意味着即使您无法处理它,也为时已晚,因为它已经被代理忘记了边。您需要使用STOMP 规范中描述的 'client' ack 或 'client-individual' ack 模式。使用一种客户端确认模式,您可以控制消息何时由代理实际确认和删除。

于 2017-11-30T15:19:37.910 回答