Spring Boot app consuming messages from Amazon MQ with Apache Camel

Matheus Silva
2 min readFeb 13, 2021

--

1. Overview

In this article, we will see how to consume messages from a queue of Amazon MQ with Spring Boot App.

PS: I won’t explain to you how to configure Amazon MQ in this article, we will just see how to consume messages.

You can check how to configure ActiveMQ on AWS here: Getting started with Amazon MQ.

2. Queue

In a queue, just one consumer will consume a message which was published.

If you need to send a message to more than one consumer, you will need to use a topic. You can read more about it, here.

3. Spring Boot App

We can use spring initializr to generate our application.

We will need these dependencies:

  • spring-boot-starter-activemq;
  • activemq-camel;
  • spring-boot-starter-web

And we will use:

  • Maven;
  • Java 8;
  • Spring Boot 2.4.2

3.1. Properties

In application.properties or application.yml, we need these properties:

spring.activemq.broker.url: When we created Amazon MQ will be generated some connections type. We will use SSL connection;
spring.activemq.user: user to connect to Amazon MQ;
spring.activemq.password: password to connect to Amazon MQ;
spring.activemq.queue.name: the name of queue;
spring.activemq.in-memory: set to false, because Spring run ActiveMQ in memory by default.

Other configurations aren’t required.

3.2. Bean Configuration

To connect to AWS MQ we need to create a bean configuration with the below code:

3.3. Apache Camel Consumer

To consume the message received we will use Apache Camel:

Again…the code is smooth and quick to write.

Done….the code is prepared to consume messages from ActiveMQ on AWS MQ.

4. Conclusion

Easy peasy right?!

It’s very simple. We need to pay attention to authorities on Amazon. Confirm if you have access to your Amazon MQ instance.

I’m doing to write an article about how to configure ActiveMQ on AMAZON MQ.

Thank you for the read.

Github: https://github.com/msilvadev/awsmq-consuming

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Matheus Silva
Matheus Silva

No responses yet

Write a response