如何使用spring框架接收所有预取rabbitmq消息? [英] How to receive all the prefetch rabbitmq messages using spring framework?

查看:45
本文介绍了如何使用spring框架接收所有预取rabbitmq消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习如何使用 SimpleMessageListenerContainer 来接收 rabbitmq 消息.我的侦听器容器具有 prefetchCount = 1000.但是我的侦听器工作人员实现了一次只接收一条消息的 MessageListener 接口.是否有接收消息列表的接口?如果没有,我该如何接收消息列表?我不想一次处理一条消息,而是处理它们的列表,这样我就可以批量插入/更新.我还想为所有发送给我的消息确认一次.

I am learning to how use SimpleMessageListenerContainer to receive rabbitmq messages. My listener container has prefetchCount = 1000. However my listener worker implements the MessageListener interface which only receive one message at a time. Is there an interface to receive a list of messages? If there is not, how can I do to receive a list of messages? I don't want to process one message at a time but rather a list of them so I can do batch insert/update. I also want to acknowledge once for all of the messages that were delivered to me.

谢谢,

肖恩·阮

推荐答案

没有这样的 API;即使是低级别的兔子客户端消费者也一次传递一条预取消息(通过 handleDelivery).

There is no such API; even the low-level rabbit client consumer delivers each prefetched message one at a time (via handleDelivery).

您必须自己将它们累积到列表中.

You will have to accumulate them into a list yourself.

使用 txSize 属性(将其设置为与预取相同)在 1000 次交付后发送单个确认.

Use the txSize property (set it the same as prefetch) to send a single ack after 1000 deliveries.

这篇关于如何使用spring框架接收所有预取rabbitmq消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆