对象消息未在 Activemq 中反序列化

Object Messages are not getting deserialised in Active MQ

我在尝试连接到 ActiveMQ 5.15.9 并获取消息时遇到以下错误。

[2019-07-16 09:25:38.61] ERRORDTL [1563269138610]javax.jms.JMSException:无法从内容构建正文。 Serializable class 不可用于代理。原因:java.lang.ClassNotFoundException:禁止classcom.xxx.yyy.zzz.aaa!此 class 不被信任序列化为 ObjectMessage 负载。请查看 http://activemq.apache.org/objectmessage.html 以获取有关如何配置受信任 classes 的更多信息。 在 org.apache.activemq.util.JMSExceptionSupport.create(JMSExceptionSupport.java:36) 在 org.apache.activemq.command.ActiveMQObjectMessage.getObject(ActiveMQObjectMessage.java:213)

为了在 ${ACTIVEMQ_HOME}/bin/env 中进行测试,我做了以下条目。

ACTIVEMQ_OPTS="$ACTIVEMQ_OPTS -Dorg.apache.activemq.SERIALIZABLE_PACKAGES=*"

并重新启动了 MQ,但我仍然遇到同样的错误。 上面使用的配置是否正确?我是否也需要在客户端使用 setTrustedPackages 或 setTrustAllPackages?

我不能发表评论,所以我 post 在这里。

您是否尝试打印系统 属性 以确保它是正确的?

对于客户端,文档说:

On the client side, you need to have this same mechanism [...]

还给出了代码示例:

The setTrustAllPackages() allows you to turn off security check and trust all classes. It’s useful for testing purposes.

ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616");
factory.setTrustAllPackages(true);

你应该为生产者和消费者写这篇文章。