Explain spring boot integration JMS (ActiveMQ Implementation)

This article introduces the integration of spring boot with JMS (ActiveMQ Implementation). I will share it with you and leave a study note for myself.

1、 Install ActiveMQ

For specific installation steps, please refer to another article: https://www.oudahe.com/p/40427/

2、 Create a new spring boot project and add JMS (ActiveMQ) dependencies

3、 Engineering structure

POM depends on the following:

4、 Modify application Properties configuration file

5、 Message producer

6、 Message consumer

The code of consumer 2 is the same as above. Note that @ component or @ service must be added to the message consumer class. In this case, the message consumer class will be delegated to the listener class. The principle is similar to using sessionawaremessagelistener and messagelistener adapter to implement message driven POJO

7、 Testing

The test results are as follows:

After the above steps, spring boot and JMS are basically integrated. Is it convenient to use!

8、 Implement bidirectional queue

1. First, we will transform the consumer 2. The code is as follows:

As can be seen from the above code, we added an annotation @ SendTo ("out. Queue") on the receivequeue method, which means to send the returned value to the "out. Queue" queue. Next, let's run the previous test. On the monitoring page, we found that there is already content in the "out. Queue" queue, as follows:

Enter the browse interface to view:

Finally, let's take a look at the specific information received:

We found that the message in the queue is the value we returned!

9、 Transformation of producer

Through the above example, we now transform producer to produce messages and consume messages in the queue. The code is as follows:

The test results are as follows:

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>