我正在运行我的代理,但是当我从队列中提取消息时遇到以下异常。
Failed to build body from content. Serializable class not available to broker. Reason: java.lang.ClassNotFoundException: Forbidden class demo.CollectorProcessInfo! This class is not trusted to be serialized as ObjectMessage payload. Please take a look at http://activemq.apache.org/objectmessage.html for more information on how to configure trusted classes.
尝试了以下链接中给出的解决方案。 SpringBoot + ActiveMQ - How to set trusted packages?
还尝试了 -Dorg.apache.activemq.SERIALIZABLE_PACKAGES = *
但没有帮助。
这是提取消息的代码
public QueueMessage pull(QUEUENAME queueName,
long timeOutInMilliSeconds) throws JMSException {
Connection connection = null;
Session session = null;
MessageConsumer consumer = null;
try{
ActiveMQJMSConnectionFactory factory = new ActiveMQJMSConnectionFactory();
connection = factory.getConnection();
connection.start();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination destination = session.createQueue(queueName.toString());
consumer = session
.createConsumer(destination);
ObjectMessage receivedMessage = (ObjectMessage) consumer.receive(timeOutInMilliSeconds);
QueueMessage message = null;
if(receivedMessage != null){
message = (QueueMessage) receivedMessage.getObject();
}
else{
logger.debug("Received message is null on a timeout");
}
return message;
}
finally{
if(consumer!=null)
consumer.close();
if(session!=null)
session.close();
if(connection!=null)
connection.close();
}
}