3 Replies Latest reply on May 21, 2009 10:20 PM by ezanih

    Send JMSMessage - JBoss ESB Ignoring MapMessage, returning n

    ezanih

      Hi there

      I am just going through the quickstart Helloworld JBossESB samples, particularly the Helloworld and the Helloworld JMS Router example. The original sample used a TextMessage type and a String as the message payload. I then played with the code and tried sending a streamable Java object (a JPA Entity) as an ObjectMessage and it worked and sent and was received successfully at the other end. I then changed to a MapMessage with the same example but I am now getting a 'Message type SpyMapMessage not supported - Message is ignored' warning and returns a null object and I am unable to read the message payload at the other end.

      Warning I am getting:

      10:19:32,812 WARN [PackageJmsMessageContents] Message type SpyMapMessage not supported - Message is ignored
      10:19:32,812 WARN [JmsGatewayListener] Action class method <process> returned a null object
      


      Why is it then when I change the sample example to a MapMessage, the listener appears to fail to detect and print it out to console?

      Here's my SendJMSMessage.java:

      
      package org.jboss.soa.esb.samples.quickstart.jmsrouter.test;
      
      
      import java.util.Properties;
      import javax.jms.JMSException;
      import javax.jms.MapMessage;
      import javax.jms.ObjectMessage;
      import javax.jms.Message;
      import javax.jms.TextMessage;
      import javax.jms.Destination;
      import javax.jms.Connection;
      import javax.jms.ConnectionFactory;
      import javax.jms.MessageProducer;
      import javax.jms.MessageConsumer;
      import javax.jms.QueueSession;
      import javax.jms.Session;
      import javax.naming.Context;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;
      
      
      
      public class SendJMSMessage
      {
       private Connection connection;
       private Session session;
       private Destination gatewayDestination;
       private Destination responseDestination;
       private Destination replyToDestination;
       private String correlationId;
      
      
      
       public void setupConnection(String destination) throws JMSException, NamingException
       {
      
      
       Properties properties1 = new Properties();
      
      
       properties1.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
       properties1.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
       properties1.put(Context.PROVIDER_URL, "jnp://127.0.0.1:1099");
      
      
       InitialContext iniCtx = new InitialContext(properties1);
      
       ConnectionFactory connectionFactory = (ConnectionFactory) iniCtx.lookup("ConnectionFactory");
      
       connection = connectionFactory.createConnection();
      
       gatewayDestination = (Destination) iniCtx.lookup("queue/quickstart_jms_router_Request_gw");
       responseDestination = (Destination)iniCtx.lookup("queue/quickstart_jms_router_routeTo");
       replyToDestination = (Destination) iniCtx.lookup("queue/quickstart_jms_router_replyToQueue");
       session = connection.createSession(false, QueueSession.AUTO_ACKNOWLEDGE);
       connection.start();
       System.out.println("Connection Started");
       }
      
       public void stop() throws JMSException
       {
       session.close();
       connection.stop();
       connection.close();
       }
      
       public void sendAMessage() throws JMSException {
       correlationId = "QuickstartId[" + java.util.Calendar.getInstance().get( java.util.Calendar.SECOND ) + "]";
       MessageProducer producer = session.createProducer(gatewayDestination);
      
       MapMessage objectMsg = session.createMapMessage();
      
       objectMsg.setString("BidderId", "1");
       objectMsg.setString("BidderSessionId", "2");
       objectMsg.setString("BidderName", "Three");
      
      
       objectMsg.setJMSCorrelationID( correlationId );
       objectMsg.setJMSReplyTo( replyToDestination );
      
       producer.send(objectMsg);
       System.out.println("Sent message with CorrelationID : " + correlationId );
       System.out.println("");
       producer.close();
       }
      
       public void receiveAMessage() throws JMSException {
      
       MessageConsumer consumer = session.createConsumer(responseDestination, "JMSCorrelationID = '" + correlationId + "'");
       Message jmsMsg = consumer.receive();
      
       System.out.println("Received from " + responseDestination + ":");
       System.out.println("\t[JMSMessageID : " + jmsMsg.getJMSMessageID() + "]" );
       System.out.println("\t[JMSCorrelelationID : " + jmsMsg.getJMSCorrelationID() + "]" );
       System.out.println("\t[JMSReplyto : " + jmsMsg.getJMSReplyTo() + "]" );
      
       if ( jmsMsg instanceof ObjectMessage )
       {
       System.out.println("\t[MessageType : ObjectMessage]");
       System.out.println( "\t[Object : " + ((ObjectMessage)jmsMsg).getObject().toString() + "]" );
       }
       else if ( jmsMsg instanceof TextMessage )
       {
       System.out.println("\t[MessageType : TextMessage]");
       System.out.println( "\t[Text : " + ((TextMessage)jmsMsg).getText() + "]" );
       }
       else if ( jmsMsg instanceof MapMessage )
       {
       String inBidderId;
       String inBidderSessionId;
       String inBidderName;
      
       System.out.println("\t[MessageType : MapMessage]");
       System.out.println( "\t[Map key/value pair (inBidderId) : " + jmsMsg.getStringProperty("inBidderId") + "]");
       System.out.println( "\t[Map key/value pair (inBidderSessionId) : " + jmsMsg.getStringProperty("inBidderSessionId") + "]");
       System.out.println( "\t[Map key/value pair (inBidderName) : " + jmsMsg.getStringProperty("inBidderName") + "]");
       }
      
       consumer.close();
       }
      
      
       public static void main(String args[]) throws Exception
       {
       SendJMSMessage sm = new SendJMSMessage();
       //sm.setupConnection(args[1]);
       //sm.setupConnection("queue/quickstart_jms_router_routeTo");
       sm.setupConnection("queue/quickstart_jms_router_Request_gw");
       sm.sendAMessage();
       sm.receiveAMessage();
       sm.stop();
       }
      
      }
      
      


      and here's MYJMSListenerAction.java:

      package org.jboss.soa.esb.samples.quickstart.jmsrouter.listener;
      
      import javax.jms.JMSException;
      import javax.jms.MapMessage;
      import javax.jms.Message;
      import javax.jms.MessageListener;
      
      
      public class MyJMSListenerAction implements MessageListener {
      
      
       public void onMessage(Message message) {
      
       MapMessage msg = (MapMessage) message;
      
       try {
      
       System.out.println("MyJMSListenerAction detected message on queue...");
       System.out.println("Bidder Id : " + msg.getString("BidderId"));
       System.out.println("Bidder Session Id : " + msg.getString("BidderSessionId"));
       System.out.println("Bidder Name : " + msg.getString("BidderName"));
      
      
       } catch (JMSException je) {
      
       System.out.println("MyJMSListenerAction - onMessage() - Exception: " + je.toString());
      
       }
      
      
       }
      
      }
      


      Here's my jboss-esb.xml:

      <?xml version = "1.0" encoding = "UTF-8"?>
      <jbossesb xmlns="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.0.1.xsd" parameterReloadSecs="5">
      
       <providers>
       <jms-provider name="JBossMessaging" connection-factory="ConnectionFactory">
      
       <jms-bus busid="quickstartGwChannel">
       <jms-message-filter
       dest-type="QUEUE"
       dest-name="queue/quickstart_jms_router_Request_gw"
       />
       </jms-bus>
       <jms-bus busid="quickstartEsbChannel">
       <jms-message-filter
       dest-type="QUEUE"
       dest-name="queue/quickstart_jms_router_Request_esb"
       />
       </jms-bus>
      
       </jms-provider>
       </providers>
      
       <services>
       <service
       category="JMSSecuredESB"
       name="SimpleListener"
       description="JMS Secured quickstart sample">
       <listeners>
       <jms-listener name="JMS-Gateway"
       busidref="quickstartGwChannel"
       is-gateway="true"
       />
       <jms-listener name="jmssecured"
       busidref="quickstartEsbChannel"/>
       </listeners>
       <actions mep="OneWay">
      
       <action name="printMessage" class="org.jboss.soa.esb.actions.SystemPrintln">
       <property name="message" value="JMS Secured Quickstart message"/>
       <property name="printfull" value="false"/>
       </action>
       <action name="routeToReplyQueue" class="org.jboss.soa.esb.actions.routing.JMSRouter">
       <!--property name="jndi-context-factory" value="org.jnp.interfaces.NamingContextFactory"/>
       <property name="jndi-URL" value="127.0.0.1:1099"/>
       <property name="jndi-pkg-prefix" value="org.jboss.naming:org.jnp.interfaces"/ -->
       <property name="connection-factory" value="ConnectionFactory"/>
       <property name="jndiName" value="queue/quickstart_jms_router_routeTo"/>
       <property name="unwrap" value="true"/>
       <property name="security-principal" value="guest"/>
       <property name="security-credential" value="guest"/>
       </action>
      
       </actions>
       </service>
       </services>
      
      </jbossesb>
      


      And finally here's my deployment.xml:

      <jbossesb-deployment>
       <depends>jboss.esb.quickstart.destination:service=Queue,name=quickstart_jms_router_Request_esb</depends>
       <depends>jboss.esb.quickstart.destination:service=Queue,name=quickstart_jms_router_Request_gw</depends>
       <depends>jboss.esb.quickstart.destination:service=Queue,name=quickstart_jms_router_routeTo</depends>
      </jbossesb-deployment>