成功测试连接后,到 IBM MQ 的 Camel jms 路由立即关闭
Camel jms route to IBM MQ immediately shuts down after successful test connection
我已经用过几次 Camel,但这个问题一直困扰着我,我不知道自己做错了什么。这是一个新的应用程序,应该从 IBM MQ 获取消息并将文件放置到磁盘。路线很简单:
String fromString = "message-queue:XXX.FUNDORDER.YYY.OUT?testConnectionOnStartup=true";
from(fromString)
.autoStartup(true)
.routeId("RouteReceiver")
.log("Processing message ${exchangeId}")
.to("file:/in?fileName=${exchangeId}.txt");
创建连接工厂时使用的代码如下:
public JmsConnectionFactory websphereConnectionFactory() throws JMSException
{
Logger logger = Logger.getLogger(Config.class);
logger.info("ibmMqChannel = " + ibmMqChannel);
logger.info("ibmMqHost = " + ibmMqHost);
logger.info("ibmMqPort = " + ibmMqPort);
logger.info("ibmMqQueueManagerName = " + ibmMqQueueManagerName);
/*
* Create MQConnectionFactory
*/
final MQConnectionFactory connectionFactory = new MQConnectionFactory();
connectionFactory.setHostName(ibmMqHost);
connectionFactory.setPort(ibmMqPort);
connectionFactory.setChannel(ibmMqChannel);
connectionFactory.setQueueManager(ibmMqQueueManagerName);
connectionFactory.setIntProperty(CommonConstants.WMQ_CONNECTION_MODE, CommonConstants.WMQ_CM_CLIENT);
logger.debug("connectionFactory=" + connectionFactory.toString());
/*
* Add ConnectionFactory to JmsConfiguration
*/
final JmsConfiguration jmsConfiguration = new JmsConfiguration();
jmsConfiguration.setConnectionFactory(connectionFactory);
/*
* Add JmsConfiguration to JmsComponent
*/
final JmsComponent jmsComponent = new JmsComponent();
jmsComponent.setConfiguration(jmsConfiguration);
jmsComponent.setAcknowledgementModeName("AUTO_ACKNOWLEDGE");
/*
* Add JmsComponent to camelContext
*/
camelContext.addComponent("message-queue", jmsComponent);
return connectionFactory;
}
应用程序启动并测试连接后,它立即开始关闭。没有异常被抛出。
在本地测试时,我使用不同的配置文件并改为连接到 ActiveMQ 服务器。这运行良好,并按预期运行。
如有任何帮助,我们将不胜感激!
/卡塔琳娜
这是路由关闭前的日志摘录:
2018-01-23 12:13:05:501 o.a.camel.component.jms.JmsConsumer DEBUG - Successfully tested JMS Connection on startup for destination: MY.QUEUE.NAME
2018-01-23 12:13:05:501 o.a.camel.component.jms.JmsConsumer TRACE - Starting listener container org.apache.camel.component.jms.DefaultJmsMessageListenerContainer@7b02881e on destination MY.QUEUE.NAME
2018-01-23 12:13:05:532 o.a.c.c.j.DefaultJmsMessageListenerContainer DEBUG - Established shared JMS Connection
2018-01-23 12:13:05:532 o.a.c.u.c.CamelThreadFactory TRACE - Created thread[Camel (Client Robur messaging service) thread #1 - JmsConsumer[MY.QUEUE.NAME]] -> Thread[Camel (Client Robur messaging service) thread #1 - JmsConsumer[MY.QUEUE.NAME],5,main]
2018-01-23 12:13:05:547 o.a.c.c.j.DefaultJmsMessageListenerContainer DEBUG - Resumed paused task: org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker@503d687a
2018-01-23 12:13:05:547 o.a.camel.component.jms.JmsConsumer DEBUG - Started listener container org.apache.camel.component.jms.DefaultJmsMessageListenerContainer@7b02881e on destination MY.QUEUE.NAME
2018-01-23 12:13:05:547 o.a.camel.spring.SpringCamelContext INFO - Route: RouteReceiver started and consuming from: message-queue://MY.QUEUE.NAME?errorHandlerLoggingLevel=TRACE&jmsMessageType=Text&testConnectionOnStartup=true
2018-01-23 12:13:05:547 o.a.camel.support.ServiceSupport TRACE - Starting service
2018-01-23 12:13:05:547 o.a.camel.spring.SpringCamelContext INFO - Total 1 routes, of which 1 are started
2018-01-23 12:13:05:547 o.a.camel.spring.SpringCamelContext INFO - Apache Camel 2.20.1 (CamelContext: Client Robur messaging service) started in 5.974 seconds
2018-01-23 12:13:05:547 o.a.camel.spring.SpringCamelContext DEBUG - start() took 5974 millis
2018-01-23 12:13:05:563 o.a.camel.spring.SpringCamelContext DEBUG - onApplicationEvent: org.springframework.boot.context.event.ApplicationReadyEvent[source=org.springframework.boot.SpringApplication@53976f5c]
2018-01-23 12:13:05:563 se.tradechannel.IbmMqApplication INFO - Started IbmMqApplication in 37.347 seconds (JVM running for 39.742)
2018-01-23 12:13:05:563 se.tradechannel.IbmMqApplication INFO - Message Queue application started.
2018-01-23 12:13:05:563 o.a.c.c.j.DefaultJmsMessageListenerContainer TRACE - runningAllowed() -> true
2018-01-23 12:13:05:766 o.a.camel.spring.SpringCamelContext DEBUG - onApplicationEvent: org.springframework.context.event.ContextClosedEvent[source=org.springframework.context.annotation.AnnotationConfigApplicationContext@621be5d1: startup date [Tue Jan 23 12:12:29 CET 2018]; root of context hierarchy]
2018-01-23 12:13:05:766 o.a.camel.spring.SpringCamelContext INFO - Apache Camel 2.20.1 (CamelContext: Client Robur messaging service) is shutting down
2018-01-23 12:13:05:766 org.apache.camel.util.ServiceHelper TRACE - Stopping service org.apache.camel.impl.DefaultRouteController@35e2d654
2018-01-23 12:13:05:766 org.apache.camel.util.ServiceHelper TRACE - Shutting down service org.apache.camel.impl.DefaultRouteController@35e2d654
2018-01-23 12:13:05:766 o.a.camel.support.ServiceSupport TRACE - Service already stopped
2018-01-23 12:13:05:766 o.a.c.impl.DefaultShutdownStrategy INFO - Starting to graceful shutdown 1 routes (timeout 300 seconds)
2018-01-23 12:13:05:766 o.a.c.m.DefaultManagementLifecycleStrategy TRACE - Checking whether to register org.apache.camel.util.concurrent.RejectableThreadPoolExecutor@279ccd56[Running, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0][ShutdownTask] from route: null
2018-01-23 12:13:05:766 o.a.c.i.DefaultExecutorServiceManager DEBUG - Created new ThreadPool for source: org.apache.camel.impl.DefaultShutdownStrategy@1e800aaa with name: ShutdownTask. -> org.apache.camel.util.concurrent.RejectableThreadPoolExecutor@279ccd56[Running, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0][ShutdownTask]
2018-01-23 12:13:05:766 o.a.c.u.c.CamelThreadFactory TRACE - Created thread[Camel (Client Robur messaging service) thread #2 - ShutdownTask] -> Thread[Camel (Client Robur messaging service) thread #2 - ShutdownTask,5,main]
2018-01-23 12:13:05:766 o.a.c.impl.DefaultShutdownStrategy DEBUG - There are 1 routes to shutdown
2018-01-23 12:13:05:766 o.a.c.impl.DefaultShutdownStrategy TRACE - Shutting down route: RouteReceiver with options [Default,CompleteCurrentTaskOnly]
2018-01-23 12:13:05:766 o.a.c.impl.DefaultShutdownStrategy TRACE - Suspending: Consumer[message-queue://MY.QUEUE.NAME?errorHandlerLoggingLevel=TRACE&jmsMessageType=Text&testConnectionOnStartup=true]
2018-01-23 12:13:05:766 org.apache.camel.util.ServiceHelper TRACE - Suspending service Consumer[message-queue://MY.QUEUE.NAME?errorHandlerLoggingLevel=TRACE&jmsMessageType=Text&testConnectionOnStartup=true]
2018-01-23 12:13:05:766 o.a.c.c.j.DefaultJmsMessageListenerContainer DEBUG - Stopping listenerContainer: org.apache.camel.component.jms.DefaultJmsMessageListenerContainer@7b02881e with cacheLevel: 3 and sharedConnectionEnabled: true
你在用SpringBoot吗?如果是,您的应用程序是否有可能不会阻塞,因此在启动后只是因为 main 方法已完成而关闭?
根据http://camel.apache.org/spring-boot.html,有很多方法可以在 SpringBoot 应用程序中阻塞主线程(有关详细信息,请参阅 Link):
- 您的路线 class 延伸
org.apache.camel.spring.boot.FatJarRouter
class
- 使用
CamelSpringBootApplicationController.blockMainThread()
- 在 pom.xml
中包含 spring-boot-starter-web
依赖项
- 在属性或YAML文件
中将属性camel.springboot.main-run-controller
设置为true
我已经用过几次 Camel,但这个问题一直困扰着我,我不知道自己做错了什么。这是一个新的应用程序,应该从 IBM MQ 获取消息并将文件放置到磁盘。路线很简单:
String fromString = "message-queue:XXX.FUNDORDER.YYY.OUT?testConnectionOnStartup=true";
from(fromString)
.autoStartup(true)
.routeId("RouteReceiver")
.log("Processing message ${exchangeId}")
.to("file:/in?fileName=${exchangeId}.txt");
创建连接工厂时使用的代码如下:
public JmsConnectionFactory websphereConnectionFactory() throws JMSException
{
Logger logger = Logger.getLogger(Config.class);
logger.info("ibmMqChannel = " + ibmMqChannel);
logger.info("ibmMqHost = " + ibmMqHost);
logger.info("ibmMqPort = " + ibmMqPort);
logger.info("ibmMqQueueManagerName = " + ibmMqQueueManagerName);
/*
* Create MQConnectionFactory
*/
final MQConnectionFactory connectionFactory = new MQConnectionFactory();
connectionFactory.setHostName(ibmMqHost);
connectionFactory.setPort(ibmMqPort);
connectionFactory.setChannel(ibmMqChannel);
connectionFactory.setQueueManager(ibmMqQueueManagerName);
connectionFactory.setIntProperty(CommonConstants.WMQ_CONNECTION_MODE, CommonConstants.WMQ_CM_CLIENT);
logger.debug("connectionFactory=" + connectionFactory.toString());
/*
* Add ConnectionFactory to JmsConfiguration
*/
final JmsConfiguration jmsConfiguration = new JmsConfiguration();
jmsConfiguration.setConnectionFactory(connectionFactory);
/*
* Add JmsConfiguration to JmsComponent
*/
final JmsComponent jmsComponent = new JmsComponent();
jmsComponent.setConfiguration(jmsConfiguration);
jmsComponent.setAcknowledgementModeName("AUTO_ACKNOWLEDGE");
/*
* Add JmsComponent to camelContext
*/
camelContext.addComponent("message-queue", jmsComponent);
return connectionFactory;
}
应用程序启动并测试连接后,它立即开始关闭。没有异常被抛出。 在本地测试时,我使用不同的配置文件并改为连接到 ActiveMQ 服务器。这运行良好,并按预期运行。
如有任何帮助,我们将不胜感激!
/卡塔琳娜
这是路由关闭前的日志摘录:
2018-01-23 12:13:05:501 o.a.camel.component.jms.JmsConsumer DEBUG - Successfully tested JMS Connection on startup for destination: MY.QUEUE.NAME
2018-01-23 12:13:05:501 o.a.camel.component.jms.JmsConsumer TRACE - Starting listener container org.apache.camel.component.jms.DefaultJmsMessageListenerContainer@7b02881e on destination MY.QUEUE.NAME
2018-01-23 12:13:05:532 o.a.c.c.j.DefaultJmsMessageListenerContainer DEBUG - Established shared JMS Connection
2018-01-23 12:13:05:532 o.a.c.u.c.CamelThreadFactory TRACE - Created thread[Camel (Client Robur messaging service) thread #1 - JmsConsumer[MY.QUEUE.NAME]] -> Thread[Camel (Client Robur messaging service) thread #1 - JmsConsumer[MY.QUEUE.NAME],5,main]
2018-01-23 12:13:05:547 o.a.c.c.j.DefaultJmsMessageListenerContainer DEBUG - Resumed paused task: org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker@503d687a
2018-01-23 12:13:05:547 o.a.camel.component.jms.JmsConsumer DEBUG - Started listener container org.apache.camel.component.jms.DefaultJmsMessageListenerContainer@7b02881e on destination MY.QUEUE.NAME
2018-01-23 12:13:05:547 o.a.camel.spring.SpringCamelContext INFO - Route: RouteReceiver started and consuming from: message-queue://MY.QUEUE.NAME?errorHandlerLoggingLevel=TRACE&jmsMessageType=Text&testConnectionOnStartup=true
2018-01-23 12:13:05:547 o.a.camel.support.ServiceSupport TRACE - Starting service
2018-01-23 12:13:05:547 o.a.camel.spring.SpringCamelContext INFO - Total 1 routes, of which 1 are started
2018-01-23 12:13:05:547 o.a.camel.spring.SpringCamelContext INFO - Apache Camel 2.20.1 (CamelContext: Client Robur messaging service) started in 5.974 seconds
2018-01-23 12:13:05:547 o.a.camel.spring.SpringCamelContext DEBUG - start() took 5974 millis
2018-01-23 12:13:05:563 o.a.camel.spring.SpringCamelContext DEBUG - onApplicationEvent: org.springframework.boot.context.event.ApplicationReadyEvent[source=org.springframework.boot.SpringApplication@53976f5c]
2018-01-23 12:13:05:563 se.tradechannel.IbmMqApplication INFO - Started IbmMqApplication in 37.347 seconds (JVM running for 39.742)
2018-01-23 12:13:05:563 se.tradechannel.IbmMqApplication INFO - Message Queue application started.
2018-01-23 12:13:05:563 o.a.c.c.j.DefaultJmsMessageListenerContainer TRACE - runningAllowed() -> true
2018-01-23 12:13:05:766 o.a.camel.spring.SpringCamelContext DEBUG - onApplicationEvent: org.springframework.context.event.ContextClosedEvent[source=org.springframework.context.annotation.AnnotationConfigApplicationContext@621be5d1: startup date [Tue Jan 23 12:12:29 CET 2018]; root of context hierarchy]
2018-01-23 12:13:05:766 o.a.camel.spring.SpringCamelContext INFO - Apache Camel 2.20.1 (CamelContext: Client Robur messaging service) is shutting down
2018-01-23 12:13:05:766 org.apache.camel.util.ServiceHelper TRACE - Stopping service org.apache.camel.impl.DefaultRouteController@35e2d654
2018-01-23 12:13:05:766 org.apache.camel.util.ServiceHelper TRACE - Shutting down service org.apache.camel.impl.DefaultRouteController@35e2d654
2018-01-23 12:13:05:766 o.a.camel.support.ServiceSupport TRACE - Service already stopped
2018-01-23 12:13:05:766 o.a.c.impl.DefaultShutdownStrategy INFO - Starting to graceful shutdown 1 routes (timeout 300 seconds)
2018-01-23 12:13:05:766 o.a.c.m.DefaultManagementLifecycleStrategy TRACE - Checking whether to register org.apache.camel.util.concurrent.RejectableThreadPoolExecutor@279ccd56[Running, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0][ShutdownTask] from route: null
2018-01-23 12:13:05:766 o.a.c.i.DefaultExecutorServiceManager DEBUG - Created new ThreadPool for source: org.apache.camel.impl.DefaultShutdownStrategy@1e800aaa with name: ShutdownTask. -> org.apache.camel.util.concurrent.RejectableThreadPoolExecutor@279ccd56[Running, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0][ShutdownTask]
2018-01-23 12:13:05:766 o.a.c.u.c.CamelThreadFactory TRACE - Created thread[Camel (Client Robur messaging service) thread #2 - ShutdownTask] -> Thread[Camel (Client Robur messaging service) thread #2 - ShutdownTask,5,main]
2018-01-23 12:13:05:766 o.a.c.impl.DefaultShutdownStrategy DEBUG - There are 1 routes to shutdown
2018-01-23 12:13:05:766 o.a.c.impl.DefaultShutdownStrategy TRACE - Shutting down route: RouteReceiver with options [Default,CompleteCurrentTaskOnly]
2018-01-23 12:13:05:766 o.a.c.impl.DefaultShutdownStrategy TRACE - Suspending: Consumer[message-queue://MY.QUEUE.NAME?errorHandlerLoggingLevel=TRACE&jmsMessageType=Text&testConnectionOnStartup=true]
2018-01-23 12:13:05:766 org.apache.camel.util.ServiceHelper TRACE - Suspending service Consumer[message-queue://MY.QUEUE.NAME?errorHandlerLoggingLevel=TRACE&jmsMessageType=Text&testConnectionOnStartup=true]
2018-01-23 12:13:05:766 o.a.c.c.j.DefaultJmsMessageListenerContainer DEBUG - Stopping listenerContainer: org.apache.camel.component.jms.DefaultJmsMessageListenerContainer@7b02881e with cacheLevel: 3 and sharedConnectionEnabled: true
你在用SpringBoot吗?如果是,您的应用程序是否有可能不会阻塞,因此在启动后只是因为 main 方法已完成而关闭?
根据http://camel.apache.org/spring-boot.html,有很多方法可以在 SpringBoot 应用程序中阻塞主线程(有关详细信息,请参阅 Link):
- 您的路线 class 延伸
org.apache.camel.spring.boot.FatJarRouter
class - 使用
CamelSpringBootApplicationController.blockMainThread()
- 在 pom.xml 中包含
- 在属性或YAML文件 中将属性
spring-boot-starter-web
依赖项
camel.springboot.main-run-controller
设置为true