[英]Receive single message from ActiveMQ queue using python STOMP
Here is the listener script which I am testing, 这是我正在测试的监听器脚本,
import stomp
import time
class SampleListener(object):
def on_message(self, headers, msg):
print(msg)
conn = stomp.Connection([('localhost',61613)])
conn.set_listener('SampleListener', SampleListener())
conn.start()
conn.connect()
conn.subscribe(destination='queue_name', id=1, ack='auto')
time.sleep(10) # secs
conn.disconnect()
If you only want to read one message at a time with STOMP the only way to do that is to use an ack mode such as client or client-individual so that the client is sent new messages only when it has sent an explicit ACK for the one's that it has. 如果您只想一次使用STOMP读取一条消息,那么唯一的方法就是使用ack模式,例如client或client-individual,这样,只有当客户端发送了明确的ACK消息时,客户端才会发送新消息。一个。 This also would require setting the prefetch value to one so that the broker doesn't send a batch of messages to the client.
这也需要将预取值设置为1,以使代理不会向客户端发送一批消息。
The STOMP Acknowledgement modes are defined in the spec here . 该STOMP确认模式在规范中定义在这里 。 The documentation for the broker's STOMP support is here .
经纪人的STOMP支持的文档在此处 。 The client sets the prefetch using the header 'activemq.prefetchSize' on the SUBSCRIBE as listed in the ActiveMQ documentation.
客户端使用ActiveMQ文档中列出的SUBSCRIBE上的标头'activemq.prefetchSize'设置预取。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.