仅使用React \ stomp消费来自RabbitMQ的N条消息,分别对其进行确认,然后退出 [英] Consume only N messages from RabbitMQ with react\stomp, ack them separately and then exit

查看:445
本文介绍了仅使用React \ stomp消费来自RabbitMQ的N条消息,分别对其进行确认,然后退出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将RabbitMQ与PHP react \ stomp一起使用.我有两个队列-一个是待办事项",另一个是完成".消费者从待办事项"中读取内容,进行工作,确认消息,然后将其发布到完成"队列中.

I am using RabbitMQ with PHP react\stomp. I have two queues - one is "todo" other is "done". Consumer reads from "todo", do its work, ACKs the message, then publishes it to the "done" queue.

有什么方法可以确保我只消耗待办事项"中的N条消息(并分别确认它们)然后退出?造成这种情况的主要原因是我们不想拥有长时间运行的使用者,而我们希望在N条消息后重新启动它们.

Is there any way of ensuring that I consume only N messages from "todo" (and ack them individually) and then quit? The main reason for that is we dont want to have long running consumers and we want to restart them after N messages.

推荐答案

您可以设置目标的预取计数:

You can set a prefetch count for a destination:

通过以下方式将所有订阅的预取计数设置为无限制 默认.这可以通过设置prefetch-count标头来控制 在SUBSCRIBE帧上达到所需的整数计数.

The prefetch count for all subscriptions is set to unlimited by default. This can be controlled by setting the prefetch-count header on SUBSCRIBE frames to the desired integer count.

https://www.rabbitmq.com/stomp.html

要仅消耗十条消息,请添加标题

So to consume only ten messages, add the header

prefetch-count:10

SUBSCRIBE框架.

您可以将确认模式设置为client-individual,以逐个消息进行手动确认.

You can set the ack mode to client-individual for message-by-message manual acknowledgement.

这篇关于仅使用React \ stomp消费来自RabbitMQ的N条消息,分别对其进行确认,然后退出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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