[jboss-user] [JBoss Messaging] - Adding properties to a received message

joshiashutosh do-not-reply at jboss.com
Wed Jul 18 05:52:29 EDT 2007


Hi,
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?

Thanks,
--Ashutosh


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4065312#4065312

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4065312



More information about the jboss-user mailing list