Getting started with Spring, RabbitMQ and Maven on MacOS

So, you want to get started with RabbitMQ in a Maven project as soon as possible? Well, bear with me here, and we’ll get you up and running in no time!

First things first: you need to install RabbitMQ. You can do this by using MacPorts:
sudo port install rabbitmq-server

After RabbitMQ has been installed and is running, it’s time to create the project. Using the following Maven POM and standard Maven structure, we create our project:

This pom.xml includes all the dependencies needed to make the client connect with RabbitMQ

Next up, is the code to receive some messages, and to produce some messages. We’ll call them the Producer and Consumer.

and the consumer:

and we’re almost done. All we need now is the Spring applicationContext.xml, which will create the RabbitMQ queue, and wire everything together:

If you start the Producer now, the Producer will send a message to the automatically created queue (you can see this in the http://localhost:55672/#/queues. When running the Consumer, it will get the message from the RabbitMQ queue, and will convert and display it in the console. Now you’ve sent your first message on RabbitMQ!