Kbase 21716: SonicMQ: MessageFormatException from MapMessage setObject
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  06/05/2003 |
|
SUMMARY:
This solution applies to SonicMQ client and explains why or when to get a MessageFormatException if trying to publish a MapMessage
and how to resolve.
EXPLANATION:
The following code will throw a javax.jms.MessageFormatException:
topic = session.createTopic("Top");
publisher = session.createPublisher(topic);
MapMessage mapmsg = publisher.createMapMessage();
mapmsg.setBoolean("Ok", true);
mapmsg.setString("JobId", "12345");
mapmsg.setInt("No", 10);
mapmsg.setObject("Obj", new MyObjectSerializable());
publisher.send(mapmsg);
The reason is that the method
public void setObject(java.lang.String name,
java.lang.Object value)
throws JMSException
of javax.jms Interface MapMessage
only works for the objectified primitive object types (Integer, Double,
Long ...), String's and byte arrays.
The MessageFormatException exception must be thrown when a JMS client
attempts to use a data type not supported by a message.
That is documented within the javax.jms interface documentation.
However the following code works as the used data type is supported:
TopicPublisher publisher = session.createPublisher(topic);
MapMessage mapmsg = session.createMapMessage();
mapmsg.setBoolean("Ok", true);
mapmsg.setString("JobId", "12345");
mapmsg.setInt("No", 10);
Object myobj = new byte[50];
mapmsg.setObject("Obj", myobj);
mapmsg.setObject("Obj2", new Integer(50));
mapmsg.setObject("Obj3", new Double(50));
mapmsg.setObject("Obj4", new Long(50));
publisher.publish(mapmsg);
SOLUTION:
An ObjectMessage can be used to send a message that contains a serializable Java object.
Note that only Serializable Java objects can be used.
References to Written Documentation:
SonicMQ API Reference (local HTML)