In this post I'm going to create a proxy service using WSO2 ESB to Pull a message from ActiveMQ and to push that Message to IBM MQ (WebSphere MQ). If you need to configure IBM MQ you can follow this Post. And to configure ESB with ActiveMQ you can follow this post.
After configuring ActiveMQ and IBM MQ you need to add the following transports. (If you have already added this do not add).
The issue here is, for both ActiveMQ and IBMMQ you need two different transport configurations. So you can achieve this by referring the following axis2 configurations.
Transport Receivers
Transport Senders
Now when you are creating a proxy the transports you defined will be listed under the transport section.
Now create the following proxy service
In the above proxy I have enabled jmsamq transport so it will Poll the queue specified for ActiveMQ and push the message to endpoint which is a queue in IBM MQ.
Also note all the header properties I have set and removed, In IBMMQ some header properties that are sent with the message may not be supported. You can refer this to get a better understanding of supported properties. So we need to specifically remove any unsupported headers if any. Or else you will come across the following error.
Hope this will help someone interested and please drop a comment if you have any queries.
After configuring ActiveMQ and IBM MQ you need to add the following transports. (If you have already added this do not add).
The issue here is, for both ActiveMQ and IBMMQ you need two different transport configurations. So you can achieve this by referring the following axis2 configurations.
Transport Receivers
<!-- This is for IBM MQ -->
<transportReceiver name="jmsin" class="org.apache.axis2.transport.jms.JMSListener">
<parameter name="default" locked="false">
<parameter name="java.naming.factory.initial" locked="false">com.sun.jndi.fscontext.RefFSContextFactory</parameter>
<parameter name="java.naming.provider.url" locked="false">file:/C:/jndi-dir</parameter>
<parameter name="transport.jms.ConnectionFactoryJNDIName" locked="false">MyQueueConnectionFactory</parameter>
<parameter name="transport.jms.ConnectionFactoryType" locked="false">queue</parameter>
<parameter name="transport.jms.UserName" locked="false">admin</parameter>
<parameter name="transport.jms.Password" locked="false">admin</parameter>
</parameter>
<parameter name="myQueueConnectionFactory1" locked="false">
<parameter name="java.naming.factory.initial" locked="false">com.sun.jndi.fscontext.RefFSContextFactory</parameter>
<parameter name="java.naming.provider.url" locked="false">file:/C:/jndi-dir</parameter>
<parameter name="transport.jms.ConnectionFactoryJNDIName" locked="false">MyQueueConnectionFactory</parameter>
<parameter name="transport.jms.ConnectionFactoryType" locked="false">queue</parameter>
<parameter name="transport.jms.UserName" locked="false">admin</parameter>
<parameter name="transport.jms.Password" locked="false">admin</parameter>
</parameter>
</transportReceiver>
<!-- This is for ActiveMQ -->
<transportReceiver name="jmsamq" class="org.apache.axis2.transport.jms.JMSListener">
<parameter name="myTopicConnectionFactory" locked="false">
<parameter name="java.naming.factory.initial" locked="false">org.apache.activemq.jndi.ActiveMQInitialContextFactory</parameter>
<parameter name="java.naming.provider.url" locked="false">tcp://localhost:61616</parameter>
<parameter name="transport.jms.ConnectionFactoryJNDIName" locked="false">TopicConnectionFactory</parameter>
<parameter name="transport.jms.ConnectionFactoryType" locked="false">topic</parameter>
</parameter>
<parameter name="myQueueConnectionFactory" locked="false">
<parameter name="java.naming.factory.initial" locked="false">org.apache.activemq.jndi.ActiveMQInitialContextFactory</parameter>
<parameter name="java.naming.provider.url" locked="false">tcp://localhost:61616</parameter>
<parameter name="transport.jms.ConnectionFactoryJNDIName" locked="false">QueueConnectionFactory</parameter>
<parameter name="transport.jms.ConnectionFactoryType" locked="false">queue</parameter>
</parameter>
<parameter name="default" locked="false">
<parameter name="java.naming.factory.initial" locked="false">org.apache.activemq.jndi.ActiveMQInitialContextFactory</parameter>
<parameter name="java.naming.provider.url" locked="false">tcp://localhost:61616</parameter>
<parameter name="transport.jms.ConnectionFactoryJNDIName" locked="false">QueueConnectionFactory</parameter>
<parameter name="transport.jms.ConnectionFactoryType" locked="false">queue</parameter>
</parameter>
</transportReceiver>
<!-- For IBM MQ -->
<transportSender name="jms" class="org.apache.axis2.transport.jms.JMSSender">
<parameter name="default" locked="false">
<parameter name="java.naming.factory.initial" locked="false">com.sun.jndi.fscontext.RefFSContextFactory</parameter>
<parameter name="java.naming.provider.url" locked="false">file:/C:/jndi-dir</parameter>
<parameter name="transport.jms.ConnectionFactoryJNDIName" locked="false">MyQueueConnectionFactory</parameter>
<parameter name="transport.jms.ConnectionFactoryType" locked="false">queue</parameter>
<parameter name="transport.jms.UserName" locked="false">admin</parameter>
<parameter name="transport.jms.Password" locked="false">admin</parameter>
</parameter>
<parameter name="myQueueConnectionFactory1" locked="false">
<parameter name="java.naming.factory.initial" locked="false">com.sun.jndi.fscontext.RefFSContextFactory</parameter>
<parameter name="java.naming.provider.url" locked="false">file:/C:/jndi-dir</parameter>
<parameter name="transport.jms.ConnectionFactoryJNDIName" locked="false">MyQueueConnectionFactory</parameter>
<parameter name="transport.jms.ConnectionFactoryType" locked="false">queue</parameter>
<parameter name="transport.jms.UserName" locked="false">admin</parameter>
<parameter name="transport.jms.Password" locked="false">admin</parameter>
</parameter>
</transportSender>
Now create the following proxy service
<?xml version="1.0" encoding="UTF-8"?> <proxy xmlns="http://ws.apache.org/ns/synapse" name="LocalQueue1" transports="jmsamq" statistics="disable" trace="disable" startOnLoad="true"> <target> <inSequence> <property name="FORCE_SC_ACCEPTED" value="true" scope="axis2"/> <property name="OUT_ONLY" value="true" scope="default" type="STRING"/> <property name="JMS_COORELATION_ID" value="12345" scope="axis2" type="STRING"/> <property name="JMS_DESTINATION" scope="transport" action="remove"/> <property name="JMS_REDELIVERED" scope="transport" action="remove"/> <property name="JMS_TYPE" scope="transport" action="remove"/> <property name="Accept-Encoding" scope="transport" action="remove"/> <property name="Content-Length" scope="transport" action="remove"/> <property name="Content-Type" scope="transport" action="remove"/> <property name="User-Agent" scope="transport" action="remove"/> <property name="Transfer-Encoding" scope="transport" action="remove"/> <property name="X-Forwarded-For" scope="transport" action="remove"/> <property name="X-Forwarded-Host" scope="transport" action="remove"/> <property name="X-Forwarded-Server" scope="transport" action="remove"/> <log level="full"/> </inSequence> <endpoint> <address uri="jms:/LocalQueue1?transport.jms.ConnectionFactoryJNDIName=MyQueueConnectionFactory&java.naming.factory.initial=com.sun.jndi.fscontext.RefFSContextFactory&java.naming.provider.url=file:/C:/jndi-dir/&transport.jms.DestinationType=queue&"/> </endpoint> </target> <description/> </proxy>
In the above proxy I have enabled jmsamq transport so it will Poll the queue specified for ActiveMQ and push the message to endpoint which is a queue in IBM MQ.
Also note all the header properties I have set and removed, In IBMMQ some header properties that are sent with the message may not be supported. You can refer this to get a better understanding of supported properties. So we need to specifically remove any unsupported headers if any. Or else you will come across the following error.
[2015-12-28 14:41:58,817] INFO - ProxyServiceDeployer ProxyService named 'EsbMQMtmOutbound' has been update from file : C:\apps\wso2\wso2esb-4.8.1\repository\deployment\server\synapse-configs\default\proxy-services\EsbMQMtmOutbound.xml [2015-12-28 14:42:26,233] ERROR - JMSSender Error creating a JMS message from the message context com.ibm.msg.client.jms.DetailedMessageFormatException: JMSCC0049: The property name 'Content-Type' is not a valid Java(t m) identifier. The supplied property name does not conform to the allowed format described in the JMS specification. Check the characters used in the property name and modify as necessary. at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:526) at com.ibm.msg.client.commonservices.j2se.NLSServices.createException(NLSServices.java:319) at com.ibm.msg.client.commonservices.nls.NLSServices.createException(NLSServices.java:233) at com.ibm.msg.client.jms.internal.JmsErrorUtils.createException(JmsErrorUtils.java:109) at com.ibm.msg.client.jms.internal.JmsMessageImpl.checkPropName(JmsMessageImpl.java:2033) at com.ibm.msg.client.jms.internal.JmsMessageImpl.setStringProperty(JmsMessageImpl.java:1559) at com.ibm.jms.JMSMessage.setStringProperty(JMSMessage.java:1496) at org.apache.axis2.transport.jms.JMSUtils.setTransportHeaders(JMSUtils.java:316) at org.apache.axis2.transport.jms.JMSSender.createJMSMessage(JMSSender.java:449) at org.apache.axis2.transport.jms.JMSSender.sendOverJMS(JMSSender.java:175) at org.apache.axis2.transport.jms.JMSSender.sendMessage(JMSSender.java:157) at org.apache.axis2.transport.base.AbstractTransportSender.invoke(AbstractTransportSender.java:112) at org.apache.axis2.engine.AxisEngine$TransportNonBlockingInvocationWorker.run(AxisEngine.java:626) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:744) [2015-12-28 14:42:26,324] INFO - AxisEngine [MessageContext: logID=3283eebc6424ae00536a3adb43db8bf0cf6e3c456624e6fc] Er ror creating a JMS message from the message context [2015-12-28 14:42:26,326] ERROR - AsyncCallback Error creating a JMS message from the message context org.apache.axis2.AxisFault: Error creating a JMS message from the message context at org.apache.axis2.transport.base.AbstractTransportSender.handleException(AbstractTransportSender.java:226) at org.apache.axis2.transport.jms.JMSSender.sendOverJMS(JMSSender.java:177) at org.apache.axis2.transport.jms.JMSSender.sendMessage(JMSSender.java:157) at org.apache.axis2.transport.base.AbstractTransportSender.invoke(AbstractTransportSender.java:112) at org.apache.axis2.engine.AxisEngine$TransportNonBlockingInvocationWorker.run(AxisEngine.java:626) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:744) Caused by: com.ibm.msg.client.jms.DetailedMessageFormatException: JMSCC0049: The property name 'Content-Type' is not a v alid Java(tm) identifier. The supplied property name does not conform to the allowed format described in the JMS specification. Check the characters used in the property name and modify as necessary. at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:526) at com.ibm.msg.client.commonservices.j2se.NLSServices.createException(NLSServices.java:319) at com.ibm.msg.client.commonservices.nls.NLSServices.createException(NLSServices.java:233) at com.ibm.msg.client.jms.internal.JmsErrorUtils.createException(JmsErrorUtils.java:109) at com.ibm.msg.client.jms.internal.JmsMessageImpl.checkPropName(JmsMessageImpl.java:2033) at com.ibm.msg.client.jms.internal.JmsMessageImpl.setStringProperty(JmsMessageImpl.java:1559) at com.ibm.jms.JMSMessage.setStringProperty(JMSMessage.java:1496) at org.apache.axis2.transport.jms.JMSUtils.setTransportHeaders(JMSUtils.java:316) at org.apache.axis2.transport.jms.JMSSender.createJMSMessage(JMSSender.java:449) at org.apache.axis2.transport.jms.JMSSender.sendOverJMS(JMSSender.java:175) ... 6 more [2015-12-28 14:42:26,336] WARN - AsyncCallback Executing fault handler due to exception encountered [2015-12-28 14:42:26,339] WARN - EndpointContext Endpoint : AnonymousEndpoint will be marked SUSPENDED as it failed [2015-12-28 14:42:26,340] WARN - EndpointContext Suspending endpoint : AnonymousEndpoint - current suspend duration is : 30000ms - Next retry after : Mon Dec 28 14:42:56 PST 2015
Hope this will help someone interested and please drop a comment if you have any queries.
0 comments:
Post a Comment