8 Replies Latest reply on Aug 17, 2007 10:53 AM by Mark Little

    How to use JMS Object Message

    Mihai Anescu Newbie

      Hello,

      Is there any sample/documentation about using an JMS Object Message?

      Basically I need to send some content + some extra info (metadata, filename, mimetype, size, date, etc). I also need to retrieve it once I arrive at a special action in the chain.

      Do you need to create your own gateway for doing this? Is there any workaround?

      Is this the JAVA_SERIALIZED type of message?

        • 1. Re: How to use JMS Object Message
          Burr Sutter Master

          I have tested (on SVN trunk, not MR3) sticking a HashMap into my JMS ObjectMessage and retrieving it in my action. That worked. The secret is that you need to use a serlizable object.

          Would you mind posting what your client-side JMS code would look like? A sampling of how you'll build up a message.

          Also, here is a VERY valuable tip:

          <action name="dump" class="org.jboss.soa.esb.actions.SystemPrintln">
           <property name="printfull" value="true"/>
          </action>
          


          Helps you find all the hidden data in the Message. We plan to map out where our gateways stick the data but we are still working on that. Please feel free to experiment and create some wiki pages for us! :-)

          Burr

          • 2. Re: How to use JMS Object Message
            Mihai Anescu Newbie

            Hello,

            Well, we're using MR3 for the moment, I guess we'll step to the next "oficial" release.

            The client code tries to send a DTO, which for now has 3 fields, one is a byte[], 2 are String. The class is serializable. So I guess it should work to get the object back in an action.

            However we would probably use this kind of JMS object message to send data from various sources, with various metadata (so yes, the best way would be some kind of Map, I guess), so the best way to transform the serialized DTO into a ESB message would be a specific JMS gateway?

            • 3. Re: How to use JMS Object Message
              Mark Little Master

               

              "burrsutter" wrote:
              I have tested (on SVN trunk, not MR3) sticking a HashMap into my JMS ObjectMessage and retrieving it in my action. That worked. The secret is that you need to use a serlizable object.


              It's not really a trick ;-) If you check the API http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/jms/ObjectMessage.html it has to be a serializable object. Nothing we're doing wrong here, for a change ;-)

              • 4. Re: How to use JMS Object Message
                Burr Sutter Master

                I should have checked in my little test as a quickstart but have since lost it. I'll have to remember to do that.

                If I remember it correctly the JMS message creator (I think of it as the client) can use something like:

                ObjectMessage tm = session.createObjectMessage(myHashMap);

                This assume your message creation code is ESB unaware, it is sending JMS messages to a queue/topic and doesn't know the ESB is there.

                However, you could also build an ESB aware client, one that understands there is an ESB:

                 Map myMap = new HashMap();
                
                 myMap.put("Key1","Value1");
                 myMap.put("anInt", new Integer(5));
                 myMap.put("aFloat",new Float(1.06));
                 requestMessage.getBody().add("myMap",myMap);
                
                 invoker.deliverAsync(requestMessage);
                


                Please feel free to make a copy of the HelloWorld example to add both JMS client (unaware) and ESB client (aware) examples where the data is passed in via Hashmap. I don't expect to have time for a proper quickstart example for the next several days.

                Next release should be around end of Aug/first week of Sept. There will be several new quickstarts showing off new functionality.

                • 5. Re: How to use JMS Object Message
                  Mihai Anescu Newbie

                  Ok then, let me try to explain different.

                  We have a set of actions, that work for all gateways so far (FS, FTP and so on).

                  Now we will have a new kind of entry, which will be an Object Message JMS gateway. We NEED to have all working as for the other gateways, so that means I guess transforming the Object JMS into a ESB usual Message (the content of the message should be the same as if sent from an FTP gateway, for example).

                  So this will mean:
                  1) define a JMS gateway that accepts our DTO Object Message
                  2) define internal JMS ESB aware listener that receives an ordinary message.

                  What I'm thinking here, correct me if I'm wrong, is that we would need to define our own custom JMS gateway to do the translation, right?
                  Or you have a generic Object JMS gateway that can be used to translate from an Object Message into a "text" message + metadata (something like a generic gateway that takes as a parameter the name of a class and the name of a method, and that method does the actual conversion, just it needs to extend a certain interface/class...)

                  • 6. Re: How to use JMS Object Message
                    Esteban Schifman Newbie

                    Just use the standard JMS gateway, and provide an appropriate composer class (the equivalent of an action class for 'gateways)

                    • 7. Re: How to use JMS Object Message
                      Mihai Anescu Newbie

                      Thanks, I'll try that.

                      • 8. Re: How to use JMS Object Message
                        Mark Little Master

                         

                        "burrsutter" wrote:

                        However, you could also build an ESB aware client, one that understands there is an ESB:
                         Map myMap = new HashMap();
                        
                         myMap.put("Key1","Value1");
                         myMap.put("anInt", new Integer(5));
                         myMap.put("aFloat",new Float(1.06));
                         requestMessage.getBody().add("myMap",myMap);
                        
                         invoker.deliverAsync(requestMessage);
                        



                        Or you could do:

                         Map myMap = new HashMap();
                        
                         myMap.put("Key1","Value1");
                         myMap.put("anInt", new Integer(5));
                         myMap.put("aFloat",new Float(1.06));
                        
                         Message requestMesssage = SerializableMessageFactory.getInstance().createMapMessage(myMap);
                        
                         // play with To, ReplyTo etc.
                        
                         invoker.deliverAsync(requestMessage);