rabbitMQ series of advanced integrated applications rabbitTemplate

RabbitMQ message template -RabbitTemplate spring of integration

RabbitTemplate: message template. It's spring rabbit integration provides message templates. It is the class key of the transmitted message.

This article has Kaige Java (kaigejava) released

Features:

This class provides a wealth of transmission method, the method comprising the reliability of message delivery, message callback listener interfaces ConfirmCallback, the return value of the interface ReturnCallBack like confirmation. Similarly, we need to inject into the spring container, then you can think of other bean as normal use.

Code Example:

1: RabbitMQConfig Add rabbit class Template statement:

/**
声明rabbitTemplate
@param connectionFactory
@return
*/
public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory){
   RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
   return  rabbitTemplate;
}



image1.png

After this, template spring container was managed. When in use, it can be directly autoWried.

In the test class:

image2.png

Start the test class, the control station the received message queue to see:

image3.png

We see, queue001 there a message.

In the page control table, find the corresponding queue. We used here is queue001 point into view:

image4.png

You can get messages as seen in FIG. Click to get Messages button, we'll get to.

image5.png

We can see that in the data headers. Attr This is our extra added. It is also received into.

Description, we use a simple message template has been successful.

This article is " RabbitMQ succinctly series" tutorial: RabbitMQ succinctly series Chapter 20. Advanced Integration Application Title III  rabbitTemplate objects . Series of tutorials, recommended to see from the first chapter. 

Kaige personal blog: www.kaigejava.com

Original Source: http: //kaigejava.com/article/detail/534


Under Section notice: SimpleMessageListenerContainer



Guess you like

Origin blog.51cto.com/kaigejava/2427574