2 Replies Latest reply on Dec 2, 2009 4:33 PM by Daniel Bevenius

    How does two esb service comminicate together?

    Younes Yahyaoui Novice

      hi,

      i want to implement two services in jboss esb, which communicate together (e.g ein servcie send a message to an other service). can someone tell me how does an esb service interact with an other esb service?

      i have an exmaple implemented but there was a problem.

      the code of the jboss-esb.xml is the following:

      
      <?xml version="1.0"?>
      <jbossesb parameterReloadSecs="5"
       xmlns="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.0.1.xsd"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.0.1.xsd http://anonsvn.labs.jboss.com/labs/jbossesb/trunk/product/etc/schemas/xml/jbossesb-1.0.1.xsd">
       <providers>
       <jms-provider connection-factory="ConnectionFactory" name="JBossMQ">
       <jms-bus busid="quickstartGwChannel">
       <jms-message-filter
       dest-name="queue/quickstart_helloworld_Request_gw_fcd" dest-type="QUEUE"/>
       </jms-bus>
       <jms-bus busid="quickstartEsbDataImporterChannel">
       <jms-message-filter
       dest-name="queue/quickstart_helloworld_Request_esb_DataImporter" dest-type="QUEUE"/>
       </jms-bus>
       <jms-bus busid="quickstartEsbFilterChannel">
       <jms-message-filter
       dest-name="queue/quickstart_helloworld_Request_esb_Filter" dest-type="QUEUE"/>
       </jms-bus>
       </jms-provider>
       </providers>
       <services>
       <service category="FirstServiceFCDKette"
       description="Import the Date from a data Provider" name="Data_Importer">
       <listeners>
       <jms-listener busidref="quickstartGwChannel" is-gateway="true" name="JMS-Gateway"/>
       <jms-listener busidref="quickstartEsbDataImporterChannel" name="Listener-DataImporter-ESB-Aware"/>
       </listeners>
       <actions mep="OneWay">
       <action class="de.dlr.ts.tdp.services.DataImporter"
       name="DisplayMessage" process="display_Message_DataImporter"/>
       </actions>
       </service>
       <service category="Second-Service-FCD-Kette"
       description="filter the message incomed from data importer" name="Filter">
       <listeners>
       <jms-listener busidref="quickstartEsbFilterChannel" name="Listener-Filter-ESB-Aware"/>
       </listeners>
       <actions mep="OneWay">
       <action class="de.dlr.ts.tdp.services.Filter" name="action_filter" process="display_Message_Filter"/>
       </actions>
       </service>
       </services>
      </jbossesb>
      
      


      the code of the first service is the following:

      
      package de.dlr.ts.tdp.services;
      
      import java.util.Properties;
      
      import javax.jms.JMSException;
      import javax.jms.ObjectMessage;
      import javax.jms.Queue;
      import javax.jms.QueueConnection;
      import javax.jms.QueueConnectionFactory;
      import javax.jms.QueueSender;
      import javax.jms.QueueSession;
      import javax.naming.Context;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;
      
      import org.jboss.soa.esb.actions.AbstractActionLifecycle;
      import org.jboss.soa.esb.helpers.ConfigTree;
      import org.jboss.soa.esb.message.Message;
      
      public class DataImporter extends AbstractActionLifecycle {
      
       protected ConfigTree _config;
       QueueConnection conn;
       QueueSession session;
       Queue que;
      
       public DataImporter(ConfigTree config) {
       _config = config;
       // TODO Auto-generated constructor stub
       }
      
       public Message display_Message_DataImporter(Message msg) throws JMSException, NamingException {
       String newMessage ="Body :" +msg.getBody().get()+ "--DataImporter--";
       System.out.println(newMessage);
       setupConnection();
       sendMessage(newMessage);
       stop();
       return msg;
       }
      
       public void setupConnection() 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);
      
       Object tmp = iniCtx.lookup("ConnectionFactory");
       QueueConnectionFactory qcf = (QueueConnectionFactory) tmp;
       conn = qcf.createQueueConnection();
       que = (Queue) iniCtx
       .lookup("queue/quickstart_helloworld_Request_esb_Filter");
       session = conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
       conn.start();
       System.out.println("Connection Started from DataImporter");
       }
      
       public void stop() throws JMSException{
       conn.stop();
       session.close();
       conn.close();
       }
      
       public void sendMessage(String msg) throws JMSException{
       QueueSender send= session.createSender(que);
       ObjectMessage tm= session.createObjectMessage(msg);
       send.send(tm);
       send.close();
       }
      
      }
      
      


      the code of the second service is the following:

      
      package de.dlr.ts.tdp.services;
      
      import org.jboss.soa.esb.actions.AbstractActionLifecycle;
      import org.jboss.soa.esb.helpers.ConfigTree;
      import org.jboss.soa.esb.message.Message;
      
      public class Filter extends AbstractActionLifecycle{
      
       protected ConfigTree _config;
      
       public Filter(ConfigTree config) {
      
       _config= config;
       // TODO Auto-generated constructor stub
       }
      
       public Message display_Message_Filter(Message msg){
       System.out.println("Filter ist aufgeweckt!!!");
       System.out.println("Signatur Filter:" +msg.getBody().get());
       return msg;
       }
      
      }
      
      


      An extern client send a message to the first service, which send it with a signature to the second service. The code of an extern client is :

      package de.dlr.ts.tdp.client;
      
      import java.util.Properties;
      
      import javax.jms.JMSException;
      import javax.jms.ObjectMessage;
      import javax.jms.Queue;
      import javax.jms.QueueConnection;
      import javax.jms.QueueConnectionFactory;
      import javax.jms.QueueSender;
      import javax.jms.QueueSession;
      import javax.naming.Context;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;
      
      public class SendJMSMessage {
      
       QueueConnection conn;
       QueueSession session;
       Queue que;
      
      
       public void setupConnection() 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);
      
      
       Object tmp= iniCtx.lookup("ConnectionFactory");
       QueueConnectionFactory qcf= (QueueConnectionFactory)tmp;
       conn = qcf.createQueueConnection();
       que= (Queue)iniCtx.lookup("queue/quickstart_helloworld_Request_gw_fcd");
       session= conn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
       conn.start();
       System.out.println("Connection Started from Client");
       }
      
       public void stop() throws JMSException{
       conn.stop();
       session.close();
       conn.close();
       }
      
       public void sendMessage(String msg) throws JMSException{
       QueueSender send= session.createSender(que);
       ObjectMessage tm= session.createObjectMessage(msg);
       send.send(tm);
       send.close();
      
      
       }
       /**
       * @param args
       * @throws NamingException
       * @throws JMSException
       */
       public static void main(String[] args) throws JMSException, NamingException {
       // TODO Auto-generated method stub
       SendJMSMessage sm= new SendJMSMessage();
       sm.setupConnection();
       //for (int i=0; i<10; i++)
       sm.sendMessage("Test TDP");
       sm.stop();
      
      
       }
      
      }
      


      deployement.xml is the followeing:
      <jbossesb-deployment>
      <depends>jboss.esb.quickstart.destination:service=Queue,name=quickstart_helloworld_Request_esb_DataImporter</depends>
      <depends>jboss.esb.quickstart.destination:service=Queue,name=quickstart_helloworld_Request_esb_Filter</depends>
      <depends>jboss.esb.quickstart.destination:service=Queue,name=quickstart_helloworld_Request_gw_fcd</depends>
      </jbossesb-deployment>
      


      jbm-queue-service.xml is :

      <?xml version="1.0" encoding="UTF-8"?>
      <server>
       <mbean code="org.jboss.jms.server.destination.QueueService"
       name="jboss.esb.quickstart.destination:service=Queue,name=quickstart_helloworld_Request_esb_DataImporter"
       xmbean-dd="xmdesc/Queue-xmbean.xml">
       <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
       <depends>jboss.messaging:service=PostOffice</depends>
       </mbean>
       <mbean code="org.jboss.jms.server.destination.QueueService"
       name="jboss.esb.quickstart.destination:service=Queue,name=quickstart_helloworld_Request_esb_Filter"
       xmbean-dd="xmdesc/Queue-xmbean.xml">
       <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
       <depends>jboss.messaging:service=PostOffice</depends>
       </mbean>
       <mbean code="org.jboss.jms.server.destination.QueueService"
       name="jboss.esb.quickstart.destination:service=Queue,name=quickstart_helloworld_Request_gw_fcd"
       xmbean-dd="xmdesc/Queue-xmbean.xml">
       <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
       <depends>jboss.messaging:service=PostOffice</depends>
       </mbean>
      </server>
      


      can someone help me please.

      thanks in advance

        • 1. Re: How does two esb service comminicate together?
          Younes Yahyaoui Novice

          uuupps the problem was :

          10:04:17,609 ERROR [JmsComposer] Object in JMS message is not a Serializeable
          java.io.IOException: Util.deserialize caught XMLStreamException
           at org.jboss.soa.esb.util.Util.deserialize(Util.java:224)
           at org.jboss.internal.soa.esb.couriers.helpers.JmsComposer.compose(JmsComposer.java:72)
           at org.jboss.internal.soa.esb.couriers.JmsCourier.pickup(JmsCourier.java:388)
           at org.jboss.internal.soa.esb.couriers.TwoWayCourierImpl.pickup(TwoWayCourierImpl.java:240)
           at org.jboss.internal.soa.esb.couriers.TwoWayCourierImpl.pickup(TwoWayCourierImpl.java:216)
           at org.jboss.soa.esb.listeners.message.MessageAwareListener.waitForEventAndProcess(MessageAwareListener.java:280)
           at org.jboss.soa.esb.listeners.message.MessageAwareListener.doRun(MessageAwareListener.java:248)
           at org.jboss.soa.esb.listeners.lifecycle.AbstractThreadedManagedLifecycle.run(AbstractThreadedManagedLifecycle.java:115)
           at java.lang.Thread.run(Unknown Source)
          Caused by: com.ctc.wstx.exc.WstxUnexpectedCharException: Unexpected character 'B' (code 66) in prolog; expected '<'
           at [row,col {unknown-source}]: [1,1]
           at com.ctc.wstx.sr.StreamScanner.throwUnexpectedChar(StreamScanner.java:623)
           at com.ctc.wstx.sr.BasicStreamReader.nextFromProlog(BasicStreamReader.java:2047)
           at com.ctc.wstx.sr.BasicStreamReader.next(BasicStreamReader.java:1069)
           at com.ctc.wstx.sr.BasicStreamReader.nextTag(BasicStreamReader.java:1095)
           at org.jboss.internal.soa.esb.util.stax.StreamHelper.skipToNextStartElement(StreamHelper.java:293)
           at org.jboss.internal.soa.esb.util.stax.StreamHelper.checkNextStartTag(StreamHelper.java:335)
           at org.jboss.soa.esb.util.Util.deserialize(Util.java:217)
           ... 8 more
          


          • 2. Re: How does two esb service comminicate together?
            Daniel Bevenius Master

            Hi,

            i want to implement two services in jboss esb, which communicate together (e.g ein servcie send a message to an other service). can someone tell me how does an esb service interact with an other esb service?

            Take a look at org.jboss.soa.esb.actions.StaticRouter, there is a quickstart named static_router which you can try out and see if it fits your use case.

            Regards,

            /Daniel