4 Replies Latest reply on Jul 20, 2007 5:30 AM by Ashutosh Joshi

    Adding properties to a received message

    Ashutosh Joshi Newbie

      I am using Jboss Messaging for my project. One of my requirements is that I wish to add some properties to the message received from one queue and put it on another queue.
      The problem is that properties of a received message are read-only and adding properties gives a MessageNotWriteableException.
      The two ways I can think of, of dealing with this problem are:
      1. Create a new message, copy all properties of the old message to the new message and then add new properties as follows:
      ObjectMessage newMessage = null;
      String name = null;
      Object value = null;
      try {
      newMessage = producerSession.createObjectMessage();
      Enumeration propNames = message.getPropertyNames();
      while (propNames.hasMoreElements()) {
      name = propNames.nextElement();
      value = message.getObjectProperty(name);
      newMessage.setObjectProperty(name, value);
      catch (JMSException jmse) {
      logger.warn("Unable to set message property " + name + " !");
      message = null;
      message = newMessage;

      2. Save the message properties (say, in a hash), call clearProperties, put the properties back and add the new properties.

      Is there a better way of adding properties? If not, which of the above methods is better?