Spring Integrated JMS Usage

Source: Internet
Author: User

Spring Integrated JMS Usage

The JMS full name Java Message Service, which is used to send messages.

1. Advantages

1. Relative RPC achieves the decoupling effect: Decoupling from the Service Interface name (changing the interface name in RPC, the client needs to make modifications), decoupling from the service location (RPC needs to configure the service's network location to use the service), and the availability of the service is decoupled (when the service is unavailable in RPC), The client is not functioning properly).
2. Avoid waiting , the client will send the message to the message agent, then can be busy with other things, and do not need to block waiting.

2. Main concepts

1. Message Broker: Ensure that the information is delivered to the specified destination while releasing the sender so that it can continue with other business. You can make an analogy with the post office in real life.
2. Destination: There are two types of destinations: queues and themes. The point-to-point message model and the publish-subscribe message model are respectively mapped. The destination is not concerned about who takes the message, only about where the message should be obtained, so the destination is similar to the address of the letter "local resident".
-Point-to-point message model: Each message in the model has a sender and receiver, the message agent obtains the message into the queue, and the recipient requests the next hop message in the queue, and the message is taken out of the queue and posted to the recipient. Messages are removed from the queue after they are posted, ensuring that messages are delivered intelligently to a recipient. Each message can only be delivered to one recipient, but it does not mean that only one recipient can be used to get the message from the queue.
-Publish-Subscribe message model: Messages are sent to a topic, similar to a queue, where multiple receivers can listen to a topic, except that messages are delivered to only one recipient in the queue, and all subscribers in the subject receive this message.

3, spring in the message agent building

Using ACTIVEMQ in this article, the ACTIVEMQ release package downloads the binary release package and executes the ACTIVEMQ start command in the Bin directory to start the service.
1 Creating a connection factory: Tell spring how to connect to the ACTIVEMQ service

<bean id ="connectionFactory" class="org.apache.activemq.spring.ActiveMQConnectionFactory">    <property name="brokerURL" value="tcp://localhost:61616">

2. Declare ACTIVEMQ destination: Regardless of the queue or topic, you need to use a specific message broker implementation class to configure the destination bean in spring

<bean id="Queue" class="Org.apahce.activemq.command.ActiveMQQueue ">    <constructor-arg value="Spitter.queue"></Bean><bean id= "topic" class=" Org.apache.actrivemq.command.ActiveMQTopic ">    <constructor-arg value="Spitter.topic"></Bean>

Where the <constructor-arg> queue name is specified

Spring Integrated JMS Usage

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.