我有一个用例,其中我需要根据某些路由规则使用Rabbitmq或ibm mq中间件,我正在使用基于Java的配置。这是我的Rabbitmq豆,如何为IBM MQ定义相似的东西?
@Bean
@ServiceActivator(inputChannel = "rabbitChannel")
public AmqpOutboundEndpoint amqpOutbound(AmqpTemplate amqpTemplate) {
AmqpOutboundEndpoint outbound = new AmqpOutboundEndpoint(amqpTemplate);
outbound.setExpectReply(true);
outbound.setExchangeName(this.exchange);
outbound.setOutputChannelName("rabbitoutChannel");
return outbound;
}
@Bean
public ConnectionFactory connectionFactory() {
CachingConnectionFactory connectionFactory = new CachingConnectionFactory(this.rabbitHost);
connectionFactory.setVirtualHost(this.vhost);
connectionFactory.setUsername(this.rabbitUserName);
connectionFactory.setPassword(this.rabbitPassord);
return connectionFactory;
}
这是JMS配置
@Bean
@ServiceActivator(inputChannel = "ibmmqChannel")
public JmsOutboundGateway jmsOutbound() {
JmsOutboundGateway outbound = new JmsOutboundGateway();
outbound.setConnectionFactory(jmsFactory());
outbound.setRequestDestinationName(this.ibmqueue);
outbound.setOutputChannelName("ibmmqoutChannel");
return outbound;
}
@Bean
public com.ibm.mq.jms.MQQueueConnectionFactory jmsFactory() {
com.ibm.mq.jms.MQQueueConnectionFactory factory = new com.ibm.mq.jms.MQQueueConnectionFactory();
factory.setHostName(this.ibmHost);
try {
factory.setQueueManager(this.ibmqManager);
factory.setPort(this.ibmPort);
factory.setChannel(this.ibmqChannel);
} catch (JMSException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return factory;
}
这是pom条目
<dependency>
<groupId>com.ibm</groupId>
<artifactId>com.ibm.mq</artifactId>
</dependency>
<dependency>
<groupId>com.ibm</groupId>
<artifactId>com.ibm.mq.allclient</artifactId>
</dependency>
<dependency>
<groupId>com.ibm</groupId>
<artifactId>com.ibm.mq.jmqi</artifactId>
</dependency>
<dependency>
<groupId>com.ibm</groupId>
<artifactId>com.ibm.mqjms</artifactId>
</dependency>
当我触发路由到IBM MQ的消息时,我看到以下错误
org.springframework.messaging.MessageHandlingException: nested exception is com.ibm.msg.client.jms.DetailedJMSException: JMSFMQ6312: An exception occurred in the Java(tm) MQI.
The Java(tm) MQI has thrown an exception describing the problem.
See the linked exception for further information.
at org.springframework.integration.jms.JmsOutboundGateway.handleRequestMessage(JmsOutboundGateway.java:778) ~[spring-integration-jms-5.0.3.RELEASE.jar:5.0.3.RELEASE]
at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:109) ~[spring-integration-core-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:127) ~[spring-integration-core-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:116) ~[spring-integration-core-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:148) ~[spring-integration-core-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:121) ~[spring-integration-core-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:89) ~[spring-integration-core-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:423) ~[spring-integration-core-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:373) ~[spring-integration-core-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:115) ~[spring-messaging-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:45) ~[spring-messaging-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.messaging.core.AbstractMessageSendingTemplate.send(AbstractMessageSendingTemplate.java:105) ~[spring-messaging-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.integration.router.AbstractMessageRouter.handleMessageInternal(AbstractMessageRouter.java:194) ~[spring-integration-core-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:127) ~[spring-integration-core-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:116) ~[spring-integration-core-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:148) ~[spring-integration-core-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:121) ~[spring-integration-core-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:89) ~[spring-integration-core-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:423) ~[spring-integration-core-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:373) ~[spring-integration-core-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:115) ~[spring-messaging-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:45) ~[spring-messaging-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.messaging.core.AbstractMessageSendingTemplate.send(AbstractMessageSendingTemplate.java:105) ~[spring-messaging-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.integration.handler.AbstractMessageProducingHandler.sendOutput(AbstractMessageProducingHandler.java:358) ~[spring-integration-core-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.integration.handler.AbstractMessageProducingHandler.produceOutput(AbstractMessageProducingHandler.java:269) ~[spring-integration-core-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.integration.handler.AbstractMessageProducingHandler.sendOutputs(AbstractMessageProducingHandler.java:186) ~[spring-integration-core-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:115) ~[spring-integration-core-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:127) ~[spring-integration-core-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:116) ~[spring-integration-core-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:148) ~[spring-integration-core-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:121) ~[spring-integration-core-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:89) ~[spring-integration-core-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:423) ~[spring-integration-core-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:373) ~[spring-integration-core-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:115) ~[spring-messaging-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:45) ~[spring-messaging-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.messaging.core.AbstractMessageSendingTemplate.send(AbstractMessageSendingTemplate.java:105) ~[spring-messaging-4.3.9.RELEASE.jar:4.3.9.RELEASE]
at org.springframework.integration.endpoint.MessageProducerSupport.sendMessage(MessageProducerSupport.java:188) ~[spring-integration-core-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.integration.kafka.inbound.KafkaMessageDrivenChannelAdapter.access$300(KafkaMessageDrivenChannelAdapter.java:69) ~[spring-integration-kafka-3.0.2.RELEASE.jar:3.0.2.RELEASE]
at org.springframework.integration.kafka.inbound.KafkaMessageDrivenChannelAdapter$IntegrationRecordMessageListener.onMessage(KafkaMessageDrivenChannelAdapter.java:375) ~[spring-integration-kafka-3.0.2.RELEASE.jar:3.0.2.RELEASE]
at org.springframework.integration.kafka.inbound.KafkaMessageDrivenChannelAdapter$IntegrationRecordMessageListener.onMessage(KafkaMessageDrivenChannelAdapter.java:352) ~[spring-integration-kafka-3.0.2.RELEASE.jar:3.0.2.RELEASE]
at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.doInvokeRecordListener(KafkaMessageListenerContainer.java:1001) [spring-kafka-2.1.3.RELEASE.jar:2.1.3.RELEASE]
at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.doInvokeWithRecords(KafkaMessageListenerContainer.java:981) [spring-kafka-2.1.3.RELEASE.jar:2.1.3.RELEASE]
at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.invokeRecordListener(KafkaMessageListenerContainer.java:932) [spring-kafka-2.1.3.RELEASE.jar:2.1.3.RELEASE]
at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.invokeListener(KafkaMessageListenerContainer.java:801) [spring-kafka-2.1.3.RELEASE.jar:2.1.3.RELEASE]
at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.run(KafkaMessageListenerContainer.java:689) [spring-kafka-2.1.3.RELEASE.jar:2.1.3.RELEASE]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_161]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_161]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_161]
Caused by: com.ibm.msg.client.jms.DetailedJMSException: JMSFMQ6312: An exception occurred in the Java(tm) MQI.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_161]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_161]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_161]
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_161]
at com.ibm.msg.client.commonservices.j2se.NLSServices.createException(NLSServices.java:319) ~[com.ibm.mq.allclient-1.0.jar:8.0.0.4 - p800-004-151023.TRIAL]
at com.ibm.msg.client.commonservices.nls.NLSServices.createException(NLSServices.java:226) ~[com.ibm.mq.allclient-1.0.jar:8.0.0.4 - p800-004-151023.TRIAL]
at com.ibm.msg.client.wmq.factories.WMQConnectionFactory.createV7ProviderConnection(WMQConnectionFactory.java:8445) ~[com.ibm.mq.allclient-1.0.jar:8.0.0.4 - p800-004-151023.TRIAL]
at com.ibm.msg.client.wmq.factories.WMQConnectionFactory.createProviderConnection(WMQConnectionFactory.java:7814) ~[com.ibm.mq.allclient-1.0.jar:8.0.0.4 - p800-004-151023.TRIAL]
at com.ibm.msg.client.jms.admin.JmsConnectionFactoryImpl._createConnection(JmsConnectionFactoryImpl.java:299) ~[com.ibm.mq.allclient-1.0.jar:8.0.0.4 - p800-004-151023.TRIAL]
at com.ibm.msg.client.jms.admin.JmsConnectionFactoryImpl.createConnection(JmsConnectionFactoryImpl.java:236) ~[com.ibm.mq.allclient-1.0.jar:8.0.0.4 - p800-004-151023.TRIAL]
at com.ibm.mq.jms.MQConnectionFactory.createCommonConnection(MQConnectionFactory.java:6024) ~[com.ibm.mq.allclient-1.0.jar:8.0.0.4 - p800-004-151023.TRIAL]
at com.ibm.mq.jms.MQQueueConnectionFactory.createQueueConnection(MQQueueConnectionFactory.java:111) ~[com.ibm.mq.allclient-1.0.jar:8.0.0.4 - p800-004-151023.TRIAL]
at com.ibm.mq.jms.MQQueueConnectionFactory.createConnection(MQQueueConnectionFactory.java:187) ~[com.ibm.mq.allclient-1.0.jar:8.0.0.4 - p800-004-151023.TRIAL]
at org.springframework.integration.jms.JmsOutboundGateway.createConnection(JmsOutboundGateway.java:1253) ~[spring-integration-jms-5.0.3.RELEASE.jar:5.0.3.RELEASE]
at org.springframework.integration.jms.JmsOutboundGateway.sendAndReceiveWithoutContainer(JmsOutboundGateway.java:861) ~[spring-integration-jms-5.0.3.RELEASE.jar:5.0.3.RELEASE]
at org.springframework.integration.jms.JmsOutboundGateway.handleRequestMessage(JmsOutboundGateway.java:742) ~[spring-integration-jms-5.0.3.RELEASE.jar:5.0.3.RELEASE]
... 48 common frames omitted
Caused by: com.ibm.mq.jmqi.JmqiException: CC=2;RC=2495;AMQ8568: The native JNI library 'mqjbnd64' was not found. For a client installation this is expected. [3=mqjbnd64]
at com.ibm.mq.jmqi.local.LocalMQ.loadLib(LocalMQ.java:1296) ~[com.ibm.mq.allclient-1.0.jar:8.0.0.4 - p800-004-151023.TRIAL]
at com.ibm.mq.jmqi.local.LocalMQ$1.run(LocalMQ.java:309) ~[com.ibm.mq.allclient-1.0.jar:8.0.0.4 - p800-004-151023.TRIAL]
at java.security.AccessController.doPrivileged(Native Method) ~[na:1.8.0_161]
at com.ibm.mq.jmqi.local.LocalMQ.initialise_inner(LocalMQ.java:259) ~[com.ibm.mq.allclient-1.0.jar:8.0.0.4 - p800-004-151023.TRIAL]
at com.ibm.mq.jmqi.local.LocalMQ.initialise(LocalMQ.java:221) ~[com.ibm.mq.allclient-1.0.jar:8.0.0.4 - p800-004-151023.TRIAL]
at com.ibm.mq.jmqi.local.LocalMQ.<init>(LocalMQ.java:1350) ~[com.ibm.mq.allclient-1.0.jar:8.0.0.4 - p800-004-151023.TRIAL]
at com.ibm.mq.jmqi.local.LocalServer.<init>(LocalServer.java:230) ~[com.ibm.mq.allclient-1.0.jar:8.0.0.4 - p800-004-151023.TRIAL]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_161]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_161]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_161]
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_161]
at com.ibm.mq.jmqi.JmqiEnvironment.getInstance(JmqiEnvironment.java:706) ~[com.ibm.mq.allclient-1.0.jar:8.0.0.4 - p800-004-151023.TRIAL]
at com.ibm.mq.jmqi.JmqiEnvironment.getMQI(JmqiEnvironment.java:640) ~[com.ibm.mq.allclient-1.0.jar:8.0.0.4 - p800-004-151023.TRIAL]
at com.ibm.msg.client.wmq.factories.WMQConnectionFactory.createV7ProviderConnection(WMQConnectionFactory.java:8437) ~[com.ibm.mq.allclient-1.0.jar:8.0.0.4 - p800-004-151023.TRIAL]
... 57 common frames omitted
Caused by: java.lang.UnsatisfiedLinkError: no mqjbnd64 in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867) ~[na:1.8.0_161]
at java.lang.Runtime.loadLibrary0(Runtime.java:870) ~[na:1.8.0_161]
at java.lang.System.loadLibrary(System.java:1122) ~[na:1.8.0_161]
at com.ibm.mq.jmqi.local.LocalMQ.loadLib(LocalMQ.java:1240) ~[com.ibm.mq.allclient-1.0.jar:8.0.0.4 - p800-004-151023.TRIAL]
... 70 common frames omitted
答案 0 :(得分:1)
因此,您只需为JMS声明一对类似的bean,并在路由器的映射中使用两个输入通道:
@Bean
@ServiceActivator(inputChannel = "jmsChannel")
public JmsOutboundGateway jmsOutbound(ConnectionFactory connectionFactory) {
JmsOutboundGateway outbound = new JmsOutboundGateway();
outbound.setConnectionFactory(connectionFactory);
outbound.setRequestDestinationName(this.jmsQueueName);
outbound.setOutputChannelName("jmsoutChannel");
return outbound;
}
@Bean
public ConnectionFactory connectionFactory() {
return new CachingConnectionFactory([TARGET_JMS_CONNECTION_FACTORY]);
}