Hello group, I'm trying to implement the sending and receiving of object messages. The class is already serializable and I can send it without problems:
Sonic.Jms.Message Msg = Sess.createObjectMessage(MP);
Prod.send(Msg);
MP is the instance of the class I'm sending.
My problem is at the receiving side, the message is triggering the onMessage event and I already have a variable with the definition of the class, but, what method should I use?
I see the getObjectProperty method from the Message class but don't know what name to use as property.
Should I use another method?
Any idea?
Thanks in advance.
Fidencio Monroy.
javax.jms.Message has the getObjectProperty(String name) method. This is used to get JMS properties (cast as an Object) -- so you might do 'getObjectProperty("JMSCorrelationID").
What you want is to get the message's body. To do this, you need to get the accessor appropriate to the subclass of message. So in the onMessage(msg) method, you want to:
so something like.
public void onMessage( javax.jms.Message aMessage)
{
try
{
// Cast the message as a Object message, if possible.
// Otherwise report that invalid message arrived.
if (aMessage instanceof javax.jms.ObjectMessage)
{
javax.jms.ObjectMessage objMessage = (javax.jms.ObjectMessage) aMessage;try
{
Object MP = objMessage.getObject();
}
catch (javax.jms.JMSException jmse)
{
jmse.printStackTrace();
}
}
else
{
System.out.println ("warning: Message arrived but cannot be " +
"processed as a javax.jms.ObjectMessage.");
}
}
catch (java.lang.RuntimeException rte)
{
rte.printStackTrace();
}
}
See the following doc in your install-dir/Docs7.6/api
file:///C:/Sonic/Docs7.6/api/sonicmq_api/javax/jms/ObjectMessage.html
Excellent, thank you very much William