ACTIVEMQ Message Delivery model

Source: Internet
Author: User
Tags sub domain

Regardless of which JMS component is used, JMS supports two distinct messaging models: PTP ( the point-to-point model) and Pub/sub (the publish/Subscribe model), respectively: PTP Domain and Pub/sub domain.


PTP (using queue as the queuing target)

Messages are routed from one producer to one consumer. In this delivery model, the target is a queue. The message is first routed to the queue target, and then, based on the queue routing policy, the message is routed from that queue to one of the consumers registered with the queue, sending only one message at a time. There is no limit to the number of producers that can send messages to the queue target, but each message can only be sent to and used successfully by a consumer. If there is no consumer registered to the queue target, the queue retains the message it receives and sends the message to the consumer when a consumer registers with the queue.


Pub/sub (use topic as theme target)

Messages are transferred from one producer to any number of consumers. In this delivery model, the target is a topic. The message is first routed to the subject target and then routed to all active consumers who have subscribed to the topic. There is no limit to the number of producers who can send messages to the subject target, and each message can be sent to any number of subscribers.


Persistent and non-persistent subscribers:

A non-persistent subscription can receive a message sent to a topic only if the client is active, that is, and the JMS Provider remains connected, and when the client is offline, messages sent to the topic during this time period are lost and never received.

A persistent subscription indicates that the consumer has registered with the subject target, but this consumer can be inactive when the message is delivered. When this consumer is again active, it will receive this information. If there are no consumers who have already registered with the subject target, the subject does not retain the messages it receives unless a persistent subscription is registered with an inactive consumer.

When a persistent subscription is made, the client registers an ID of its own identity with the JMS server, and when the client is offline, JMS Provider stores all messages sent to the topic for that ID, and when the customer connects to the JMS Provider again, All messages that are sent to the topic when they are offline are given according to their ID.



code example:

Create connectionconnection = Connectionfactory.createconnection (); Connection.setclientid ("BBB"); This must be set for persistent subscriptions. Connection.start ();//Create sessionsession session = Connection.createsession (False,session.auto_acknowledge);// Create Destinationtopic topic = Session.createtopic ("Usersynctopic"); Topic name//messageconsumer consumer = session.createconsumer (topic); General subscription Messageconsumer consumer = session.createdurablesubscriber (topic, "BBB"); Persistent subscription


This article is from the "Nothing-skywalker" blog, please be sure to keep this source http://tianxingzhe.blog.51cto.com/3390077/1686401

ACTIVEMQ Message Delivery model

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.