A collection object containing Serializable, non-primitive objects cannot be set as ActiveMQ ObjectMessage

I would be grateful for any help in this ...

I have an object that I am trying to send to the JMS ObjectMessage by calling setObject. This object contains HashMap content, as well as some other fields. When the map contains primitive elements, the message is built perfectly. Similarly, if I add a non-primitive serializable field to the primitive, it will also send ok.

Here's rub: whenever I try to add a serializable non-primitive object to the MAP, I get the following MessageFormatException:

javax.jms.MessageFormatException: Only objectified primitive objects, String, Map and List types are allowed but was: com.abc.ObjectInList 

javadoc for ObjectMessage indicates ...

Only Serializable Java objects can be used.

... check. AND...

If you need to submit a collection of Java objects, you can use one of the Collection classes provided with JDK 1.2.

... double check. Although this does not say anything about serializable objects in the collection, I assume that it will be supported. Am I something wrong here? I just bite a bullet and create a new field in my top-level object, so I don't need to put it in a collection?

Using ActiveMQ 5.2. An appropriate stack trace follows.

2011-08-01 21: 06: 05,767 ERROR javax.jms.MessageFormatException: only objectified primitive objects, types String, Map and List are allowed, but this is: com.abc.engine.ejb.BasicSchedule@58f295b9 Type: class with om.abc.engine.ejb.BasicSchedule 2011-08-01 21: 06: 05,767 ERROR at org.apache.activemq.command.ActiveMQMessage.checkValidObject (ActiveMQMessage.java:468) 2011-08-01 21: 06: 05,767 ERROR at org.apache.activemq.command. ActiveMQMapMessage.setObject (ActiveMQMapMessage.java:705) 2011-08-01 21: 06: 05,767 ERROR on com.abc.chronicle.ejb.ChronicleMessageBean.initMessage (ChronicleMessageBean.java:149) 2011-08-01 21:06:19: 05.767 ERROR on com.abc.chronicle.ejb.ChronicleMessageBean.send (ChronicleMessageBean.java:125) 2011-08-01 21:06:05: 057 ERROR on com.abc.chronicle.ejb.ChronicleMessageBean.onMessage (ChronicleMessageBean.java77) 2011-08-01 21: 06: 05,767 ERROR at sun.reflect.NativeMethod AccessorImpl.invoke0 (native method) 2011-08-01 21: 06: 05,768 ERROR on sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:39) 2011-08-01 21: 06: 05,777 ERROR [com.abc.chronicle .ejb.ChronicleMessageBean] JMS Exception Sending a message to SDK.OUTGOING_NOTIFICATION: javax.jms.MessageFormatException: only objectified primitive objects, String, Ma p and list types are allowed, but were: com.abc.engine.ejb.BasicSchedule@1003b2df Type: class com.abc.engine. ejb.BasicSchedule 2011-08-01 21: 06: 05,778 ERROR javax.jms.MessageFormatException: only objectified primitive objects are allowed, the types String, Map and List, but this: com.abc.engine.ejb.BasicSchedule@1003b2df Type: class om om.abc.engine. ejb.BasicSchedule 2011-08-01 21: 06: 05,778 ERROR on org.apache.activemq.command.ActiveMQMessage.checkValidObject (ActiveMQMessage.java:468) 2011-08-01 21:06: 05,778 ERROR on org.apache.activemq.command.ActiveMQMapMessage.setObject (ActiveMQMapMessage.java:705) 2011-08-01 21:06:05,778 ERROR on com .abc.chronicle.ejb.ChronicleMessageBean.initMessage (ChronicleMessageBean.java:149) 2011-08-01 21: 06: 05,778 ERROR on com.abc.chronicle.ejb.ChronicleMessageBean.send (ChronicleMessageBean.java:125) 2011-08 -01 21: 06: 05,778 ERROR on com.abc.chronicle.ejb.ChronicleMessageBean.onMessage (ChronicleMessageBean.java:77)

+6
source share
1 answer

Although I have not tested it yet, but looking at the source code , it seems that you are caught in this exception when ActiveMQ checks the property message, not the body. The JavaDoc for ObjectMessage reads:

Only Serializable Java objects can be used.

I used all kinds of Java objects with ActiveMQ (arbitrary complex) and it always worked. However, when you set the properties of the message ( Message # setObjectProperty ):

Please note that this method only works for objectified primitive object types ( Integer , Double , Long ...) and String objects.

By checking the ActiveMQ codebase above, it looks like you are trying to use the properties of a message object to send complex Java objects. This violates the concept of message properties, which should be simple metadata, such as identifiers or peer names.

ActiveMQ also seems to optionally support Map and List , but it is a specific provider.

+6
source

Source: https://habr.com/ru/post/894060/


All Articles