12

I want to see content of message which have been queued in ActiveMQ queues. I opened web-console.(http://localhost:8161/admin/queues.jsp) and clicked on message-id of the message of queue. It gives me following error in "Message Details" window rather than giving content of message.

"javax.jms.JMSException: Failed to build body from content. Serializable class not available to broker. Reason: java.lang.ClassNotFoundException:"

What is the cause of this exception & what I need to do to get rid of this?

OwlR
  • 409
  • 1
  • 5
  • 19
  • 1
    have a look at http://codeomitted.com/failed-to-build-body-from-content-serializable-class-not-available-to-broker/ – Vihar Mar 30 '17 at 05:02
  • http://activemq.apache.org/objectmessage.html – quintin Sep 05 '19 at 07:57
  • If you are sending class, in this case you will face this issue. For example: customer is my class object and when you try to see the infomation it gives you error: Serializable class not available to broker: java.lang.ClassNotFoundException while viewing messages in ActiveMQ jmsTemplate.convertAndSend(jmsDestination,customer); The Solution of this problem is ("toString()") method along with class. Solution: jmsTemplate.convertAndSend(jmsDestination,customer.toString()); – Maninder Jan 14 '22 at 03:23

3 Answers3

4

I have seen this same error using ActiveMQ version 5.8.0

In my case it was a red herring, the ActiveMQ console could not unserialize the message it mustn't have access to the jar that the class is in, but the consumer application does, and the message is passed on without issue from the queue to the consumer.

I'd be interested to see if there's a solution to the issue here (viewing the message in the console), and also how this is handled in more recent versions of ActiveMQ.

chim
  • 8,407
  • 3
  • 52
  • 60
  • 3
    Reason for this is: Custom class is not in classpath of active mq broker. We can add custom classes to broker's class path by adding following in "ActiveMQ\bin\win64\wrapper.conf" file. **wrapper.java.classpath.3=** (path can be anything having custom jars) – OwlR Jul 21 '17 at 14:04
  • Thanks hyrahul64, that's one good solution. Other options would involve making all messages json style messages, but I think I would prefer adding the custom class, even though I guess it does add a maintenance issue. – chim Jul 24 '17 at 11:48
4

As OwIR mentioned, you need to set the path of the jar file containing the classes onto the wrapper.java.classpath.3 property in %ACTIVEMQ_HOME%\bin\win64\wrapper.conf.

You might encounter the below exception after updating the above property

Serializable class not available to broker. Reason: java.lang.ClassNotFoundException: Forbidden class

In order to fix it, set the wrapper.java.additional.13 property to -Dorg.apache.activemq.SERIALIZABLE_PACKAGES="<choose_the_packages_set_it_here>"

You could also use -Dorg.apache.activemq.SERIALIZABLE_PACKAGES="*" as the value, however it might be unsafe to use wildcard.

This worked for me!! Hope it helps you

Kamal
  • 69
  • 4
  • stuck in the same situation and the above solution doesn't work for me. my active MQ broker version is 5.16.0 and i can easily consume the messages as i have set trusted packages on my consumer and producers along with custom jar in broker class path and wrapper.conf property set. need help. – JayD Dec 15 '20 at 14:49
  • well i got it to work i just ran the activemq.bat file present in the win64 folder of the binary because that's where i was changing the wrapper.conf file and now i am able to view the message body of an object message from the web console – JayD Dec 16 '20 at 06:16
  • Hi @JayD I'm using Activemq 5.16.3. after adding property wrapper.java.additional.13=Dorg.apache.activemq.SERIALIZABLE_PACKAGES="*" in %ACTIVEMQ_HOME%\bin\win64\wrapper.conf not working and even after run activemq.bat file present in the win64 folder also doesn't help for me. still i'm getting "Cannot display ObjectMessage body. Reason: Failed to build body from content. Serializable class not available to broker. Reason: java.lang.ClassNotFoundException: org.apache.synapse.message.store.impl.commons.StorableMessage" in Activemq message section. Can you help me on this? – Justin Dec 23 '21 at 16:43
0
If you are sending class, in this case you will face this issue.

For example: customer is my class object and when you try to see the infomation it gives you error:
Serializable class not available to broker: java.lang.ClassNotFoundException while viewing messages in ActiveMQ

jmsTemplate.convertAndSend(jmsDestination,customer);

The Solution of this problem is ("toString()") method along with class.

Solution: jmsTemplate.convertAndSend(jmsDestination,customer.toString());
Maninder
  • 1,539
  • 1
  • 10
  • 12