https://grokonez.com/spring-framework/spring-amqp/springboot-rabbitmq-headers-exchange

SpringBoot RabbitMq Headers Exchange

In the past post, we had introduced about RabbitMQ Topic Exchange. Today, JavaSampleApproach will show you how to work with SpringBoot RabbitMQ Headers Exchange.

Related posts:

I. Technologies

– Java 8 – Maven 3.6.1 – Spring Tool Suite – Version 3.8.1.RELEASE – Spring Boot: 1.5.7.RELEASE – RabbitMQ

II. RabbitMq Headers Exchange

Headers exchange routes message based on header values instead of routing keys. A special argument named x-match has 2 values {all, any} where all is the default value of a headers binding. - x-match = all means that all the values must match. - x-match = any means just one matching header value is sufficient. springboot rabbitmq exchage headers - architecture design

Scenarios with above design:

  • When sending a message with headers: {layer=system, level=error}, the message will be delivered to 2 queues {Q1, Q2}.
  • When sending a message with headers: {layer=application, level=error}, the message will be delivered to one queue Q2.
  • When sending a message with headers: {layer=system, level=info}, the message will be discarded.

III. Practices

In the tutorial, we create 2 SpringBoot project as below: springboot rabbitmq exchage headers - project structures

Step to do:
– Create SpringBoot projects
– Implement RabbitMq producer
– Implement RabbitMq consumer
– Run and check results

1. Create SpringBoot projects

Using SpringToolSuite, create 2 SpringBoot projects, then add need dependency spring-boot-starter-amqp:

https://grokonez.com/spring-framework/spring-amqp/springboot-rabbitmq-headers-exchange

SpringBoot RabbitMq Headers Exchange

#springboot #rabbitmq #header-exchange

SpringBoot RabbitMq Headers Exchange » grokonez
2.00 GEEK