Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to publish a serialized Java object to a JMS topic on the WSO2 ESB
    text
    copied!<p>I am trying to setup a publish and subscribe scenario using the WSO2 ESB, WSO2 MB and JMS topics.</p> <p>In the publishing proxy, my endpoint service will return a Java message that implements Serializable and in the proxy's out sequence, should publish the message to the JMS topic.</p> <p>Below is a copy of my proxy:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;proxy xmlns="http://ws.apache.org/ns/synapse" name="MyProxy" transports="https,http" statistics="disable" trace="disable" startOnLoad="true"&gt; &lt;target endpoint="conf:/MyService"&gt; &lt;inSequence&gt; &lt;log level="full"/&gt; &lt;/inSequence&gt; &lt;outSequence&gt; &lt;log level="full"/&gt; &lt;property name="OUT_ONLY" value="true" scope="default" type="STRING"/&gt; &lt;send&gt; &lt;endpoint&gt; &lt;address uri="jms:/MyTopic?transport.jms.ConnectionFactoryJNDIName=TopicConnectionFactory&amp;amp;java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory&amp;amp;java.naming.provider.url=tcp://localhost:61616&amp;amp;transport.jms.DestinationType=topic"/&gt; &lt;/endpoint&gt; &lt;/send&gt; &lt;/outSequence&gt; &lt;/target&gt; &lt;description/&gt; &lt;/proxy&gt; </code></pre> <p>What I've tried:</p> <ol> <li><p>My endpoint service returns a custom Java object that implements Serializable, i.e.:</p> <pre><code>public MyMessage MyService.processMessage( String inMsg ) { return new MyMessage(); } </code></pre> <p>Result: From the Log Mediator the message published looks like a SoapEnvelope where the payload is the base64necoded response of MyMessage in XML form.</p></li> <li><p>My endpoint service returns a JMS ObjectMessage which contains MyMessage as its object. i.e.:</p> <pre><code>public ObjectMessage MyService.processMessage(String inMsg) throws Exception { // build myMessage MyMessage myMsg = new MyMessage(); // Build JMS message // Obtain a JNDI connection using the jndi.properties file String topicFactory = "TopicConnectionFactory"; // is this value correct? InitialContext ctx = new InitialContext(); // Look up a JMS connection factory and create the connection TopicConnectionFactory conFactory = (TopicConnectionFactory)ctx.lookup(topicFactory); TopicConnection connection = conFactory.createTopicConnection(); TopicSession pubSession = connection.createTopicSession( false, Session.AUTO_ACKNOWLEDGE); ObjectMessage jmsMsg = pubSession.createObjectMessage(); jmsMsg.setObject( myMsg ); return jmsMsg; } </code></pre> <p>Result: </p> <blockquote> <p>JMSOutTransportInfo Could not get an initial context using {java.naming.provider.url=tcp:// localhost:61616, java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory, transport.jms.DestinationType=topic, transport.jms.ConnectionFactoryJNDIName=TopicConnectionFactory} javax.naming.NoInitialContextException: Failed to create InitialContext using factory specified in hash table. [Root exception is java.lang.ClassNotFoundException: class org.apache.activemq.jndi.ActiveMQInitialContextFactory not found]</p> </blockquote></li> <li><p>From attempt 2, changed <code>TopicConnectionFactory</code> to <code>myTopicConnectionFactory</code> as specific in axis2.xml file. Result: Similar error as attempt 2. </p></li> </ol> <p>My Questions:</p> <ol> <li>Should my endpoint service return MyMessage (i.e. attempt 1) or the JMS ObjectMessage containing MyMessage (attempts 2 &amp; 3)?</li> <li>For attempt 1, I expected to see binary data representing the serialized Java object instead of the message in XML in the decoded response's payload. Is this a valid expectation? </li> <li>Are there any other properties I need to set (e.g. in the proxy or endpoint) in order to mark the message as a serialized Java object before publishing to the topic?</li> </ol> <p>Thank you.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload