Springboot JMS (ActiveMQ) Usage practices

Source: Internet
Author: User

Original: 79041997

ActiveMQ

1. After downloading the activemq of Windows Office, the following directory can be started:

Spring

2. The following prompts will be available after startup

Spring

3. So we can use the HTTP://LOCALHOST:8161 Access Management page, through the tcp://localhost:61616 to connect the message server, the user name and password are in the following file (default is Admin=admin)

Spring

Springboot Connection Activemq

1. Join the dependency:

Spring-boot-starter-activemq

2. Configure the connection properties:

Spring

Sending and receiving of messages

Producer/Consumer Model

1. Create a producer

Spring

2. Create a consumer

Spring

Note: The @JmsListener is a repeatable annotation that can be replaced with @jmslisteners in JAVA7 and the following versions of the JDK.

3. Test class

Spring

4. Run the test

Spring

Publish/Subscribe Mode

1. Post a topic

Spring

2. Subscribe to the topic

Spring

Note: In pub/sub mode, the listener for a message requires the following configuration for Containerfactory

Spring

3. Testing

Spring

Spring

Application

Following the above steps, it is easy to send and receive messages for class two modes in Springboot. But JMS-specific scenarios are between different applications, where producers and consumers are often in different applications. In addition, the message in the above example we send only strings, in fact, can also send the object type of message, can even use Messagecreator custom message conversion, instead of using the Convertandsend method default conversion.

Sending messages between multiple applications

1. First use a sender, no consumer or subscriber app send two kinds of messages 10

Spring

Spring

2. We open the localhost:8161 and we can see

Spring

Spring

There were 10 messages queued in both categories, but only 10 messages were left in the queues.

3. Now we launch applications that contain consumers and subscribers

Spring

Sure enough, only the consumer received the message in queues.

This means that subscribers receiving topic are required to subscribe before topic is released, whereas in production/consumption mode, messages are placed in queues and waiting for consumers to consume.

4. We start with two programs that contain subscribers and consumers, and then post a message

Spring

Spring

Spring

Two Subscribers receive topic message 1~9, while one receives messages 1, 3, 5, 7, 9, and the other receives 0, 2, 4, 6, 8.

This means that when there are multiple message receivers, multiple consumers in production/consumption mode take turns to consume messages in the queue, and all subscribers in Pub/sub mode will receive all the messages.

Springboot JMS (ActiveMQ) Usage practices

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.