2 Replies Latest reply on Aug 21, 2008 9:17 AM by Alexandros Karypidis

    Programmatically determine which listener the message arrive

    Alexandros Karypidis Novice

      Hi,

      I need to process incoming messages (the messages are XML documents of an application-specific schema) arriving through multiple channels (JMS, Filesystem, Database Table).

      I've set up a processing action chain with three listeners: JMS, Filesystem and Database. Is there a way by which my action can know which listener the message arrived from?

      The reason I care about this is that I have found that the message body is a different type of object depending on which channel it arrives through. Therefore, to get to the content, I currently "cheat" as follows:

      Object payload = message.getBody().get();
      String messageXML;
      if (payload instanceof Map) {
       @SuppressWarnings("unchecked")
       Map<String, Object> rowData = (Map) payload;
       messageXML = (String) rowData.get("MESSAGE");
      } else if (payload instanceof byte[]) {
       messageXML = new String((byte[]) payload);
      } else {
       messageXML = payload.toString();
      }


      I am thinking of creating 3 different actions that add the channel name to the message context and then call a "common" listener (since the further processing is the same). Before I do that, I wanted to check if there is some standard API to get the name of the listener (defined in jboss-esb.xml). I was thinking I should be able to do something like:

      Object payload = message.getBody().get();
      String messageXML;
      if (message.getListener().equals("my_SQL_Listener")) {
       @SuppressWarnings("unchecked")
       Map<String, Object> rowData = (Map) payload;
       messageXML = (String) rowData.get("MESSAGE");
      } else if (message.getListener().equals("my_FS_Listener")) {
       messageXML = new String((byte[]) payload);
      } else if (message.getListener().equals("my_JMS_Listener")) {
       messageXML = payload.toString();
      }



        • 1. Re: Programmatically determine which listener the message ar
          Daniel Bevenius Master

          Hi,

          one option might be to create a custom message composers for the gateways.
          They could all place the data in the same location and make sure that it is of the the correct type. This way no extra checking would be needed in the service then.

          The composer class to be used in specified in the on the gateway listener like this:

          <fs-listener name="FileGateway" busidref="fsRef" is-gateway="true" poll-frequency-seconds="2">
           <property name="composer-class" value="yourClass"/>
           </fs-listener>
          

          You can look at the org.jboss.soa.esb.listeners.message.MessageComposer interface which you will need to implement.

          Would that be an option for you do you think?

          Regards,

          /Daniel


          • 2. Re: Programmatically determine which listener the message ar
            Alexandros Karypidis Novice

            I had a look and saw that it gives complete control over "what" the entire message is. I think I'll extend the Message class and create something like "MyMessage" that can cover anything that comes up in the future as well.

            Although these are my first steps with JBossESB, this feels much more elegant and versatile to me. Thanks for pointing me there.