Java 使用ApacheCamel定制jms侦听器
我正在使用ApacheCamel和ApacheActiveMQ,需要对连接关闭/恢复做出反应 我曾尝试使用Java 使用ApacheCamel定制jms侦听器,java,apache-camel,jms,listener,Java,Apache Camel,Jms,Listener,我正在使用ApacheCamel和ApacheActiveMQ,需要对连接关闭/恢复做出反应 我曾尝试使用ActiveMQConnectionFactoryCustomTransportListener,但无法捕捉连接恢复的时刻。所以我转向定制JmsListener 我对组件进行如下配置: private void setJms(String suffix) { ActiveMQComponent amqComponent = new ActiveMQComponent(
ActiveMQConnectionFactory
CustomTransportListener,但无法捕捉连接恢复的时刻。所以我转向定制JmsListener
我对组件进行如下配置:
private void setJms(String suffix) {
ActiveMQComponent amqComponent = new ActiveMQComponent();
JmsConfiguration jmsConfiguration = new JmsConfiguration();
Persistence persistence = AppBeans.get("cuba_Persistence");
jmsConfiguration.setExceptionListener(e -> {
log.debug("debug");
persistence.runInTransaction(em -> {
//actions
});
});
jmsConfiguration.setConsumerType(ConsumerType.Custom);
jmsConfiguration.setMessageListenerContainerFactory(MyMessageListenerContainer::new);
jmsConfiguration.setConnectionFactory(connectionFactory);
jmsConfiguration.setConcurrentConsumers(count);
jmsConfiguration.setPreserveMessageQos(true);
jmsConfiguration.setTransacted(true);
jmsConfiguration.setCacheLevelName("CACHE_CONSUMER");
amqComponent.setConfiguration(jmsConfiguration);
context.addComponent(connectionSettings.getJmsName() + suffix, amqComponent);
}
////
和侦听器扩展默认值-基本上我只需要在恢复连接后做一些事情
private class MyMessageListenerContainer extends DefaultJmsMessageListenerContainer {
public MyMessageListenerContainer(JmsEndpoint endpoint) {
super(endpoint);
}
@Override
protected void refreshConnectionUntilSuccessful() {
super.refreshConnectionUntilSuccessful();
log.debug("WHOOOF!");
}
}
我可以捕获异常,但在恢复时仍有困难。我收到以下信息:
MyMessageListenerContainer - Shutting down JMS listener container
MyMessageListenerContainer - Waiting for shutdown of message listener invokers
MyMessageListenerContainer - Still waiting for shutdown of 3 message listener invokers
有人能帮我解决我的问题吗?在验证/恢复与activemq的连接期间,可能还有其他方法来执行某些操作?
多谢各位