Spring Boot Getting Started : Async pattern and Profiling

Spring Boot Getting Started : Async pattern and Profiling


Hello friends, In our previous blog we started our Spring Boot Microservice journey, head to our Microservices Beginner to Expert series for better understanding. Today I will discuss about asynchronous communication by spring boot and spring boot profiling:

Asynchronous Communication

Asynchronous style communication is present for quite some time but AMQP ( Advanced Messaging Queueing Protocol) based messaging is now very popular communication methodology. Almost all cloud platforms support AMQP based messaging system. Here I will provide example of integration of Spring Boot with Rabbit MQ. RabbitMQ supports AMQP based messaging.

You can get details about RabbitMQ from https://www.rabbitmq.com

I believe, we already understand the below diagram , just highlighting for better visualization.

The sender drops messages to the exchange with a routing key. The message gets routed to the queue / queues associated to the exchange. Subscriber polls the queue continuously. Whenever a message gets dropped in the queue to which subscriber is listening subscriber spawns it’s message processing handler.

You can download examples of publisher and subscriber from


  • Publisher Project : SpringBpootProducer

RabbitMQ server needs to be installed in local machine and should be up and running. By default the username, password and port are as follows:

  • Username : guest
  • Password : guest
  • Port : 5672

Producer Components :

DemoApplication – This class starts a spring boot application and associates the message sender. The DemoApplication implements CommandLineRunner to automatically triger the run method. The run method invokes the sender and passes a message.

  Sender – The send(String message) method drops a message to an exchange with a routing key. This uses “RabbitTemplate” to drop a message in the exchange with a routing queue.

  Pom.xml – This contains the required maven dependencies

Consumer Components:

DemoApplication – This class starts a spring boot application. This class does the following

  • Creates Exchange Object
  • Creates Queue Object
  • Binds Exchange with a Queue for a routing key
  • Configures a listener and a callback method to be invoked when a message is received.

When a message is dropped in the queue where consumer is listening , Receiver.processMessage() method is invoked by “MessageListenerAdapter”.

Pom.xml – This contains the required maven dependencies

Spring Boot Profiling

Profiling allows the boot application to use different values for different circumstances. The circumstances may be specific to deployment environments like development, staging , production etc or other business specific values. The values are different for same property key and boot application uses the property key.

You can download the example from


Project name: SpringBpootMultipleProfile

Please check the directory path : “\src\main\resources” where you can find multiple profile specific property files:

  • properties : This is default profile
  • application-dev.properties : This is profile for development
  • application-stage.properties : This is profile for staging.

You could also specify it on the command line by using the following switch: –spring.profiles.active=dev

So that’s it for today. Please continue reading and provide your feedback. Next I will start discussing about spring cloud and platform services / supporting services.


Author: Debajyoti Mukherjee

Debajyoti Mukherjee has more than 11 years if IT experience in application design , application development. He has worked in large MNCs and has worked for eminent clients. He is proficient in custom development , cloud platform , microservice based application migration.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.