0
votes

I am trying to consume JMS messages sent via spring JmsTemplate using @Consume annotated bean. The consumer is not receiving messages when sent using JmsTemplate.

Whereas, when sent using ProducerTemplate of Camel the messages are received.

What is the difference between @org.springframework.jms.annotation.JmsListener and @org.apache.camel.Consume?

Producer Logic

jmsTemplate.convertAndSend("jms:mailbox", message);

Consumer Logic

@Consume(uri="jms:mailbox")
    public void onRequest(String name) {
        System.out.println("Received message > "+name);
    }
1

1 Answers

2
votes

Apache Camel @Consume annotation can consume from any endpoint, which supports consuming. This annotation takes uri as parameter. URI consists of scheme, path and optional params. In case of JMS component the scheme is jms, path is Destination (in your case mailbox) and params are additional options customizing behavior of Consumer.

Spring @JmsListener can consume from JMS and takes Destination as parameter.

Your code does not work because the Destination is mailbox, not jms:mailbox. Spring JmsTemplate does not know about jms scheme, it is Camel specific. So use jmsTemplate.convertAndSend("mailbox", message) on Spring side and @Consume(uri="jms:mailbox") on Camel side.