Member-only story

Spring Boot — send RabbitMQ message

theoneamin
2 min readJun 20, 2022

In this article, we’ll take a look at how to send messages to a RabbitMQ queue. RabbitMQ is an open-source message broker. It can be used in an event-driven architecture where different microservices need to communicate regardless of the programming language/framework used.

Let’s take a look at how to send messages from a spring boot application and in another article, we’ll see how to consume those messages.

The first thing to do is to get RabbitMQ. I have got mine running in docker. Then add the following dependency.

Then in application properties, add the following for connecting to RabbitMQ.

Message Producer

We’ll add a message producer by creating a component class. I’ve called mine RabbitMQMessageProducer.

We have two queues defined in this example. We also have a message converter bean and we use that in the rabbitTemplate.

Send message

With our producer created, we can autowire that in our application to send messages to any queue we create.

Thanks for reading and I hope you found this useful. Any suggestions that would be useful to other readers, please leave them in the comments.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

theoneamin
theoneamin

Responses (1)

Write a response