MQ Queue and Topic of difference

Queue (Queue) and topic (Topic) is JMS supports two messaging models:


        1, point (point-to-point, referred to as PTP) Queue messaging model:


        By this messaging model, an application (i.e. message producer) may provide another application (i.e. message consumers) message. In the transmission model, the message type is the destination queue (i.e. Destination interface implementation class instance of class instance created by the Session interface by calling its methods and createQueue incoming queue name). First message is transmitted to the server-specific message queue, and then from this column in the message sent to this queue a consumer listening. Queue may be associated with a plurality of message producers and message consumers, but only pass a message to a message consumer. If more than one message consumer is listening for messages on the queue, JMS messaging server determines which messages to receive the next message from the consumer in accordance with the principle of "first come first". If there is no message consumers listen queue, the message will remain in the queue until the message until the consumer is connected to the queue. Such messaging model or model lazy polling model in the traditional sense. In this model, the message is not automatically push the message to the consumer, but to get the request from the queue by the message consumer. 


        2, publish / subscribe (publish / subscribe, referred to as pub / sub) Topic messaging models:

        Transmitting the message through the model, an application can send a message to a plurality of message consumers. In this delivery model, the destination type is the subject of the message (ie Destination interface is implemented by the Session instance of a class instance of class that implements the interface created by calling its createTopic method and pass in the topic name). First of all messages posted by the message producer to the message server in a particular topic, and then by the message server to deliver the message to all consumers have subscribed to this topic. Topic destinations also support long-term subscriptions. Durable subscription represents a consumer has registered a topic destination, but at the time the message reaches the target consumer may be inactive. When a consumer becomes active again, it will receive the message. If consumers are not registered to a topic destination, the topic retain only durable subscriptions inactive consumer news. PTP messaging model with different, pub / sub messaging model allows multiple topic subscribers receive the same message. JMS messaging remain until all topic subscribers have so far received the message. pub / sub messaging model is basically a push model. In this model, the message will automatically broadcast, news consumers need to get a new message through polling or actively requests theme. 

        Contrast specific differences as follows:

 

Types of

Topic

Queue

Overview

Publish Subscribe messaging publish subscribe messaging

Point-to-Point Point

Whether the state

topic default data does not fall, it is stateless.

Queue default data will be saved as a file on the server mq, such as Active MQ typically stored in $ AMQ_HOME \ data \ kr-store \ data below. You may be configured to store DB.

Integrity assurance

Each publisher does not guarantee publication of data, Subscriber can receive.

Queue ensure that each receiver is able to receive data.

Whether the message will be lost

Generally when a publisher publish messages to a topic, only that topic is listening sub address can receive the message; if there is no sub listening, the topic is lost.

Sender sends a message to the target Queue, receiver may receive messages asynchronously on this Queue. Message Queue on temporarily if no receiver to take, is not lost.

Receiving news release strategy

Many receive policy news release, listen to multiple sub addresses the same topic can receive messages sent by the publisher. Sub mq after receiving notification server

One to one to receive news release strategies, messages sent by a sender, a receiver only receives. After receiving the receiver, the server has received notification mq, mq server or take other actions to delete messages in the queue.

Guess you like

Origin www.cnblogs.com/gaopengpy/p/11994984.html