Apache Camel: JMS, Spring Boot -> get the JMSMessage out of the exchange

In this little example code fragment i got some messages out of a JMS Queue. The containing JMS Message has an attribute called content but to get this, you’ll have to get the JMSMessage from the exchange Message Body and then get the JMSMessage again and cast it to an ActiveMQBytesMessage. In my case i had to use a ActiveMQ Queue, so for that reason the JMSMessage was packaged into a ActiveMQBytesMessage.

In a following post, i’ll try to give an example how you can add attachments to JMSMessages and send it to the Queue.

private void configureReadFromEmployeeQueue() {
                .log(LoggingLevel.INFO, "Reading from JMS Queue")
                .process(new Processor() {
                    public void process(Exchange exchange) throws Exception {
                        Message message = exchange.getIn();
                        JmsMessage emp = message.getBody(JmsMessage.class);
                        ActiveMQBytesMessage mes = (ActiveMQBytesMessage)emp.getJmsMessage();
                        log.info("Reading from JmsQueue: " + new String(mes.getContent().getData()));

                .log(LoggingLevel.INFO, "OK")