Search code examples
javajmsactivemq-artemis

How to get protocol in ActiveMQ Artemis via JMS?


I'm sending a message to an Artemis ActiveMQ queue, but I can't find a method to get the message protocol

Code for receiving the body of the message, but in this class I did not find a method for obtaining the protocol:

connectQueueBrowser();
Enumeration<Message> messageEnumeration =  queueBrowser.getEnumeration();
ArrayList<Message> messages = new ArrayList<>();
while (messageEnumeration.hasMoreElements()){
   messages.add(messageEnumeration.nextElement());
}
System.out.println(messages.get(0).getBody(String.class));

The Message class is in the package: import javax.jms.Message;

enter image description here


Solution

  • ActiveMQ Artemis doesn't store the which protocol sent the message. The protocol value that you see when inspecting a message via management regards how the message is stored on disk. The broker supports 2 different storage formats:

    • one for messages sent via AMQP (i.e. AMQP)
    • one for messages sent via every other protocol (i.e. CORE).

    There is no way to retrieve this data from any supported JMS Message implementation.

    It's worth noting that one of the main design elements of asynchronous messaging is a 100% decoupling of producers and consumers. In other words, producers don't care (and don't know) about consumers and consumers don't care (and don't know) about producers. Furthermore, in a properly decoupled application the consumer shouldn't care about what protocol was used to send the message. It should only care about the data in the message, regardless of how it was sent.