Spring AMQP RabbitMQ Example

Today we will look into Spring AMQP RabbitMQ example application. We have already discussed some “Spring AMQP Basics Theoretically” and “How to install and setup RabbitMQ Server” in my previous posts. Please refer them in the following:

In this post, we are going to develop a Spring AMQP RabbitMQ Messaging application. Let us start it now.

Spring AMQP RabbitMQ Example

Let us start developing a Spring AMQP RabbitMQ Messaging application using Maven, Eclipse IDE and RabbitMQ Server. It is same for all other Java IDEs.

Please do the following the steps one by one:

    1. Create a Maven Java project in Eclipse IDE
    2. Develop Spring AMQP Publisher program

    1. Configure Spring AMQP Publisher required beans : springamqp-rabbit-sender-context.xml

    1. Develop Spring AMQP Consumer(Spring MDP) program

    1. Configure Spring AMQP Consumer required beans : springamqp-rabbt-listener-context.xml

    1. Develop Spring AMQP Rabbit Container program to initialize Spring IOC Container

    1. Final pom.xml file

    1. Our Final Maven Project Structure
    2. spring_rabbitmq_amqp_example

Test Spring AMQP RabbitMQ Example with RabbitMQ Server

    1. Run AMQP Publisher and observe messages in RabbitMQ Queue
    2. spring_rabbitmq_amqp_sender (1)

Here we can see that AMQP Publisher sent 10 messages successfully.

    1. RabbitMQ console is showing 10 messages in the queue
    2. spring_rabbitmq_amqp_sender2

Here we can see that our RabbitMQ queue has received 10 messages successfully from AMQP Publisher.

    1. Run AMQP Consumer and observe messages in Eclipse IDE
    2. spring_rabbitmq_amqp_receiver (1)

Here we can see that AMQP Consumer receives each message one by one from RabbitMQ queue.

    1. RabbitMQ console is showing 0 messages in the queue
    2. spring_rabbitmq_amqp_receiver2

Here we can observe that RabbitMQ queue has 0 messages that means AMQP Consumer has received all messages successfully.

NOTE: With this knowledge of Spring AMQP RabbitMQ Messaging, you can read more about Spring AMQP API and learn new things. And also go through RabbitMQ Server documentation to get more details about Exchanges, Queues etc.

NOTE: As I told you in my previous post, both Spring AMQP API and RabbitMQ Server are from The Pivotal Team.

That’s it all about developing Spring AMQP RabbitMQ Messaging Example. We will discuss and develop Spring AMQP ActiveMQ Messaging Example in my coming posts.

Further Reading: Apache ActiveMQ.

By admin

Leave a Reply

%d bloggers like this: