简体   繁体   English

python 中的 stomp.ConnectionListener 在从 ActiveMQ 出列消息时是否保存任何数据?

[英]Does stomp.ConnectionListener in python holds any data while dequeuing messages from ActiveMQ?

I want to pull the messages from AMQ to python.我想将消息从 AMQ 拉到 python。 I want to use python for batch processing (like if I have 1000 messages in the queue, I need to dequeue every 100 messages and process them and take the next 100 messages and process...until all messages are dequeued.)我想使用 python 进行批处理(例如,如果我在队列中有 1000 条消息,我需要每 100 条消息出列并处理它们并获取接下来的 100 条消息并处理......直到所有消息都出列。)

here is my python code for batchListener:这是我的批处理监听器的 python 代码:

class BatchEventListner(stomp.ConnectionListener):
     def on_message(self, headers, message):
         print('received a message "%s"' % message)


batchLsnr = BatchEventListner()
self.conn = stomp.Connection(host_and_ports=hosts)
self.conn.set_listener('', batchLsnr)
self.batchLsnr = batchLsnr
self.conn.start()
self.conn.connect('username', 'password', wait=True)
self.conn.subscribe(destination='/queue/' + self.queue_name, id=1, ack='auto')

I wrote a simulator to push messages to AMQ.我写了一个模拟器来将消息推送到 AMQ。 once I push 1000 messages to ActiveMQ.一旦我将 1000 条消息推送到 ActiveMQ。 when the consumers start, python code will start pulling the data from ActiveMQ but python code is pulling more than 100 messages at once.当消费者启动时,python 代码将开始从 ActiveMQ 拉取数据,但 python 代码一次拉取超过 100 条消息。 (processing is happening only for 100 but more than 100 messages are getting dequeued). (仅对 100 条消息进行处理,但有超过 100 条消息正在出队)。 ie, for the last batch (100 messages), we are not seeing any messages in ActiveMQ but the messages are getting in the python process.即,对于最后一批(100 条消息),我们在 ActiveMQ 中看不到任何消息,但消息正在 python 进程中获取。

1. Does stomp holds any messages while dequeuing from ActiveMQ? 1. stomp 在从 ActiveMQ 出队时是否持有任何消息? 2. is stomp holds any data while the batch is processing? 2. 批量处理时 stomp 是否保存任何数据?

You may be seeing the result of prefetch .您可能会看到prefetch的结果。 Try setting the activemq.prefetchSize header in your SUBSCRIBE frame to 1 .尝试将SUBSCRIBE框架中的activemq.prefetchSize header 设置为1

Also, try setting your acknowledgement mode to client or client-individual .另外,尝试将您的确认模式设置为clientclient-individual Using auto will basically trigger the broker to dispatch messages to the client as fast as it can.使用auto基本上会触发代理尽可能快地向客户端发送消息。

Keep in mind that prefetching messages is a performance optimization so lowering it will potentially result in a performance drop.请记住,预取消息是一种性能优化,因此降低它可能会导致性能下降。 Of course, performance must be weighed against other factors of functionality.当然,性能必须与其他功能因素进行权衡。 I recommend you test and tune until you meet all of your goals or find an acceptable compromise between them.我建议您进行测试和调整,直到您满足所有目标或在它们之间找到可接受的折衷方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM