gpt4 book ai didi

java - 集合中包含可序列化的非原始对象的对象不能设置为 ActiveMQ ObjectMessage

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:15:02 24 4
gpt4 key购买 nike

我将不胜感激这方面的任何帮助...

我有一个对象,我试图通过调用 setObject 在 JMS ObjectMessage 中发送。该对象包含一个 HashMap 内容以及一些其他字段。本地图包含原始元素时,消息构建良好。同样,如果我向对象添加一个非原始可序列化字段,它也会发送 ok。

问题在于:每当我尝试向 MAP 添加可序列化的非原始对象时,我都会收到以下 MessageFormatException:

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

ObjectMessage 的 javadoc 指定...

Only Serializable Java objects can be used.

...检查。还有……

If a collection of Java objects must be sent, one of the Collection classes provided since JDK 1.2 can be used.

...仔细检查。虽然这并没有具体说明集合中的可序列化对象,但我想我会假设这会受到支持。我在这里做错了什么吗?我是否只是硬着头皮在我的顶级对象中创建一个新字段,这样我就不必将它放入集合中?

使用 ActiveMQ 5.2。随后是相关的堆栈跟踪。

2011-08-01 21:06:05,767 ERROR javax.jms.MessageFormatException: Only objectified primitive objects, String, Map and List types are allowed but was: com.abc.engine.ejb.BasicSchedule@58f295b9 type: class c 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 at com.abc.chronicle.ejb.ChronicleMessageBean.initMessage(ChronicleMessageBean.java:149) 2011-08-01 21:06:05,767 ERROR at com.abc.chronicle.ejb.ChronicleMessageBean.send(ChronicleMessageBean.java:125) 2011-08-01 21:06:05,767 ERROR at com.abc.chronicle.ejb.ChronicleMessageBean.onMessage(ChronicleMessageBean.java:77) 2011-08-01 21:06:05,767 ERROR at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)2011-08-01 21:06:05,768 ERROR at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 2011-08-01 21:06:05,777 ERROR [com.abc.chronicle.ejb.ChronicleMessageBean] JMS Exception Sending Message to SDK.OUTGOING_NOTIFICATION : javax.jms.MessageFormatException: Only objectified primitive objects, String, Ma p and List types are allowed but was: 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, String, Map and List types are allowed but was: com.abc.engine.ejb.BasicSchedule@1003b2df type: class c om.abc.engine.ejb.BasicSchedule 2011-08-01 21:06:05,778 ERROR at org.apache.activemq.command.ActiveMQMessage.checkValidObject(ActiveMQMessage.java:468) 2011-08-01 21:06:05,778 ERROR at org.apache.activemq.command.ActiveMQMapMessage.setObject(ActiveMQMapMessage.java:705) 2011-08-01 21:06:05,778 ERROR at com.abc.chronicle.ejb.ChronicleMessageBean.initMessage(ChronicleMessageBean.java:149) 2011-08-01 21:06:05,778 ERROR at com.abc.chronicle.ejb.ChronicleMessageBean.send(ChronicleMessageBean.java:125) 2011-08-01 21:06:05,778 ERROR at com.abc.chronicle.ejb.ChronicleMessageBean.onMessage(ChronicleMessageBean.java:77)

最佳答案

虽然我没查过,但是看source code当 ActiveMQ 验证消息 properties 而不是正文时,您似乎遇到了这个异常。 JavaDoc ObjectMessage 读取:

Only Serializable Java objects can be used.

我将各种 Java 对象与 ActiveMQ(任意复杂)一起使用,并且它总是有效。但是,当您设置消息属性(Message#setObjectProperty)时:

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

检查上面引用的 ActiveMQ 代码库,您似乎在尝试使用消息对象属性来发送复杂的 Java 对象。这滥用了消息属性的概念,消息属性应该是简单的元数据,例如 ID 或对等名称。

另外,ActiveMQ 似乎可以选择性地支持 MapList,但这是特定于供应商的。

关于java - 集合中包含可序列化的非原始对象的对象不能设置为 ActiveMQ ObjectMessage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6904048/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com