In Rabbit-based API, a statement exchange, a binding declaration stating that a queue is created out through the channel. As shown below:
So in the spring AMQP how these objects are declared?
In use springAMQP to declare, you need to use the following mode of springAMQP. That the use of @Bean mode:
Here we demonstrate the code:
On a modified code RabbitMQConfig class. Add the following:
/ **
* for the consumer configuration
* 1. Set switch type
* 2. Bind to the switch queue
FanoutExchange: the distribution message to all of the binding queues, no routingkey concept
HeadersExchange : by adding a property key-value matches
DirectExchange: According to routingkey distributed to the designated queue
TopicExchange: multi-keyword matching
* /
Description:
We need to be set according to different characteristics of the switch.
Such as the topic of:
Start test code to view the queue:
Switch View:
Check the binding relationship:
To Topic 001 this switch as an example:
Binding the two queues. Cohort 1 and cohort 3.routing Key are: the Spring . * And MQ *.. In the end right?
We look at the code:
You can see the code really is so bound. Description, we declare the queue, the binding, the switch successfully.
This article posted by Kaige Java (Kaige Java) in 51CTO. Kaige public number: Kaige Java (kaigejava). Personal blog: www.kaigejava.com
This section summarizes:
By bean annotation obtain the Exchange , the Binding , Queue object.
This article is " RabbitMQ succinctly series" tutorial: RabbitMQ succinctly series Chapter 19. Advanced integrated applications The second Spring AMQP statement . Series of tutorials, recommended to see from the first chapter .
Notice under section:
Next class, we will explain an important target rabbitTemplate objects .