如何在侦听器使用骆驼接收JMS消息之前延迟队列中的JMS消息? [英] How to delay a JMS message in queue before a listener receives it using camel?
问题描述
我正在尝试将邮件排入队列几秒钟. 但是,当我使用骆驼延迟选项时,它不会在队列中延迟,而是会立即消耗掉,并在路由路径中延迟. 我们如何才能延迟邮件,以便它们在队列中停留几秒钟?
I am trying to delay a message to be in queue for few seconds. But when I use camel delay option, it is not delaying in queue, instead it is immediately consumed, and delaying in the route path. How can we delay messages so that they will be there in queue for few seconds?
我的骆驼形弹簧如下所示.
My spring with camel configuration looks like below.
<bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
<property name="connectionFactory" ref="jmsConnectionFactory" />
</bean>
<camelContext id="camelContext" xmlns="http://camel.apache.org/schema/spring">
<route id="routeOne" delayer="10000">
<from uri="jms://queueone?concurrentConsumers=1"/>
<log message="routeOne incoming message ${body}"/>
<delay><constant>30000</constant></delay>
<process ref="loggerProcessor"/>
</route>
</camelContext>
<bean id="loggerProcessor" name="loggerProcessor" class="emh.LoggerProcessor"/>
推荐答案
通过骆驼延迟
骆驼 delay 和 throttle 将从ActiveMQ队列中删除(使用)消息并将其(在内存中)保留在路由中,直到进行处理.事务处理的JMS可能会减轻有关丢失消息的问题,但尚未尝试过. 值得思考的.
Delay via Camel
Camel delay and throttle will remove (consume) the message from ActiveMQ queue and keep it (in-memory) in the route until processed. Transacted JMS might alleviate issues concerning losing the message, haven't tried that yet. Food for thought.
我使用AMQ_SCHEDULED_DELAY
标头结合启用schedulerSupport
[ 2 , 3 , 4 , 5 , JMS 2.0传递延迟.
I got it to work in Spring Boot 2 with Camel and ActiveMQ using the AMQ_SCHEDULED_DELAY
header combined with enabling schedulerSupport
[1, 2, 3, 4, 5, 6]. This is per JMS 2.0 Delivery Delay.
请注意,只有在没有活动使用者(即应用程序关闭或骆驼路由被禁用)时,消息才会出现在ActiveMQ队列中(待处理).以下配置用于使用现有 ActiveMQ代理.
Note that a message will only appear in the ActiveMQ queue (pending) when there are no active consumers - i.e. application down or Camel route disabled. Configuration below is for using an existing ActiveMQ broker.
application.properties ( RouteBuilder
from("jms://incomingQueue").setHeader("AMQ_SCHEDULED_DELAY", constant("1000")).inOnly("jms://delayedQueue");
from("jms://delayedQueue").process(...);
activemq.xml (现有代理安装)
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="localhost" dataDirectory="${activemq.data}" schedulerSupport="true">
对于在/usr/local/Cellar/activemq/<version>/libexec/conf
下找到的OSX Homebrew.
For OSX Homebrew found under /usr/local/Cellar/activemq/<version>/libexec/conf
.
如果您想在应用程序中使用嵌入式代理,则可以使用 BrokerService .
If you want to use a broker embedded in your application you can use the BrokerService.
默认情况下,数据保留在 activemq-data 中,并且需要activemq-kahadb-store
依赖性-即使您选择了JDBC(
By default data is persisted in activemq-data and requires the activemq-kahadb-store
dependency - also if you chose JDBC (source). Using brokerService.setPersistent( false )
the store dependency is no longer required, but then the JMS message is stored in-memory again.
@Bean
public BrokerService brokerService()
{
BrokerService brokerService = new BrokerService();
brokerService.setSchedulerSupport( true );
return brokerService;
}
这篇关于如何在侦听器使用骆驼接收JMS消息之前延迟队列中的JMS消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!