kroegr / spring-boot-rabbitmq-integration-test

Spring Boot Rabbitmq With Integration Test with AMQ in memory (qpid-broker)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Spring boot Rabbitmq with integration test

This guide walks you through the process of setting up a RabbitMQ AMQP server that publishes and subscribes to messages.

We are going to configure a direct exchange binding with routing key bounded to our queues. Here is graphic definition of our direct exchange model:

Amq Definition

If it is the first time you are listening to amq concepts I will recomend you to read this link:

What you’ll build

You’ll build an application that publishes messages using Spring AMQP’s RabbitTemplate and subscribes to the message using MessageListenerAdapter. Integration Test is using qpid-broker in memory AMQP server.

App could be start by Spring boot main method sending (Application.class). If you want to run Spring Application Rabbitmq server is a must.

What you’ll need

Java 1.8 is a must

Maven/Gradle is a must

Docker will be used to run rabbitMq Server

15 minutues of your appreciated time and be patient. Programming is not a game It is a fun way to pass your weekends :)

Install tools

A Rabbitmq instance is needed to be able to test our Spring boot main project(In test folder we use qpid-broker in memory Server). Run your docker tool and search one Rabbitmq image in docker Hub. In our example bitname image will be used to run main project (https://hub.docker.com/r/bitnami/rabbitmq/)

Here you have a snapshot with Kitematic for docker:

Bitnami docker Image for Rabbitmq

Another snapshot with user and password settings:

Bitnami docker Image for Rabbitmq User and Password

In app main resources folder you can find Spring boot Config to be able to connect to Rabbitmq:

Spring boot main application.properties

Run your main boot application and access to admin console(this example is http://localhost:32807 with user/bitnami) and verify Direct Exchage and Queues have been created:

Java Configuration Beans:

Definition of queues/exchange

Exchanges: spring-boot-exchange:

Rabbitmq exchange

Queues: spring-boot and spring-boot2 queues:

Rabbitmq queues

Bindings between spring-boot-exchange and queues: spring-boot* , spring-boot2:

Rabbitmq bindings

Test folder include in memory qpid-broker :

It will send messages to exchange with a routing key. If a receiver catch a message will increase its counter.Assertion will validate correct value:

Rabbitmq bindings

About

Spring Boot Rabbitmq With Integration Test with AMQ in memory (qpid-broker)


Languages

Language:Java 100.0%