Search code examples
jmsactivemq-classicquarkussmallrye

Connecting Quarkus application to a JMS based application through ActiveMQ


I work on an application which is built on Quarkus which needs to communicate through ActiveMQ with other application. For communication with ActiveMQ I am using smallrye library. The other application is built on spring boot, and is using org.apache.activemq:activemq-client library to communicate with ActiveMQ. That application is out of my reach so I can't do the changes on it, however it might be possible to reach someone who is in charge to do small adjustments.

Having said that, I tried to make a sample code that make these two communicate. I successfully made JMS side to send messages to smallrye side, but when sending messages in other direction I was receiving messages which body contains both message body itself as well as some metadata (I can recognize some properties names) encoded at the beginning of the message body. The same/similar message content can also be seen on the ActiveMQ web interface when looking at the message sent by smallrye.

This is the code I use to send message:

        @Outgoing("outgoing-queue")
        public Multi<Message<String>> sendWithSomeMetadataSet() {
            return Multi.createFrom()
                    .ticks().every(Duration.ofSeconds(20))
                    .map(x -> Message.of("Hello"))
                    .map(m -> m.addMetadata(createMetadata("Test")));
        }
    
        static OutgoingAmqpMetadata createMetadata(String address) {
            return OutgoingAmqpMetadata.builder()
                    .withAddress(address)
                    .withApplicationProperty("foo", "bar")
                    .withApplicationProperty("brown", "fox")
                    .withDurable(true)
                    .withCreationTime(Instant.now().toEpochMilli())
                    .withExpiryTime(Instant.now().plus(12, ChronoUnit.HOURS).toEpochMilli())
             .build();
        }

On ActiveMQ web interface I can see there's a message with content like this:

Sp�APSs�%@@�Test@@@@@���;bm����4m@CSt��foo�bar�brown�foxSw�Hello

Same message content is retrieved in the JMS code. Is there something I can do on when sending this messages with smallrye to make their content readable, or is there a simple way to read this kind of messages content properly using the activemq-client library? Is there a different library that I can use on Quarkus instead of smallrye?


Solution

  • The Quarkus Smallrye client is sending AMQP messages to the broker's AMQP transport connector which would then be routing the AMQP messages without conversion (given the behavior you've described) to the broker's internal Openwire format but simply wrapping the payload which is why the JMS consumer gets a BytesMessage body that is the raw AMQP encoded bytes instead of a JMS TextMessage etc.

    What you would need to do in this case is change the broker configuration to use the appropriate message transformer. See the AMQP configuration page, namely the section on "Mapping to JMS" and the JMS transform option for details on this. This would instruct the broker to convert all incoming AMQP messages and allow the Openwire client to get a message that makes sense to them.