如何从ActiveMQ延迟使用Apache Camel中的消息 [英] How to delay consuming messages in Apache Camel from ActiveMQ

查看:202
本文介绍了如何从ActiveMQ延迟使用Apache Camel中的消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要求,当客户端应用在5秒的时间内发送超过1000个请求时,我需要通过调整(排队)入站流量来进行限制。

I have a requirement where I need to throttle by shaping (queuing) inbound traffic when client app sends more than 1000 requests in a 5 sec time span.

我遵循的解决方案是:
我有一个camel:throttle将最大请求设置为1000,时间跨度为5秒。当超过阈值时,我捕获到油门异常,并且在onException块内,我将油门消息发送到ActiveMQ请求队列,以便稍后进行进一步处理,因为Camel基于1000 req / 5 sec配置超载。

The solution I followed is: I have a camel:throttle setting max requests to 1000 and timespan to 5 sec. When threshold is exceeded I am catching throttle exception and within the onException block, I am sending the throttled messages to an ActiveMQ request queue for further processing later as Camel is overloaded based on 1000 req/ 5 sec config.

我成功地实现了上述功能,但是我希望Camel消费者以后可以进一步处理ActiveMQ请求队列中的所有消息,而不是一次处理所有消息,例如,延迟10秒

I am successful in implementing the above, however I would like to have Camel consumer to further process later not all messages from ActiveMQ request queue at one shot instead process each message with a delay of 10 sec for e.g.

我无法在ActiveMQ中设置参数来延迟向消费者发送消息,也不会延迟Camel消费者从请求队列中提取消息。

I am not able to set a parameter in ActiveMQ to say delay the message to consumer nor delay Camel consumer pulling off the message from request queue.

如何满足上述要求

请帮助

谢谢
Ramesh。

Thanks Ramesh.

推荐答案

在另一个SO中线程获胜的答案可以推广以下解决方案:

In another SO thread the winning answers promotes the following solution:

from("activemq:queueA").throttle(10).to("activemq:queueB")

对我来说,此解决方案仅在定义预取限制时才有意义,否则,消费者将不会在意下游的限制。此路由应该有效:

To me this solution only makes sense, if you define a prefetch limit, without which the consumer would not care about any downstream throttling. This route should work:

from("activemq:queueA?&destination.consumer.prefetchSize=10").throttle(10).to("activemq:queueB")

这是背后的麻烦来自 http://activemq.apache.org/what-is -the-prefetch-limit-for.html


因此ActiveMQ对可流式传输的消息使用预取限制任何时候的消费者。一旦达到预取限制,就不会再将更多的消息分发给使用者,直到使用者开始发送回消息确认(表明该消息已被处理)为止。可以根据每个使用者指定实际的预取限制值。

So ActiveMQ uses a prefetch limit on how many messages can be streamed to a consumer at any point in time. Once the prefetch limit is reached, no more messages are dispatched to the consumer until the consumer starts sending back acknowledgements of messages (to indicate that the message has been processed). The actual prefetch limit value can be specified on a per consumer basis.

这篇关于如何从ActiveMQ延迟使用Apache Camel中的消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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