Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the queue and topic message sending and receiving model

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

ActiveMQ is a very popular message queuing service middleware, based on JMS (Java Message Service) specification, and it is a pure Java program, the running environment only needs a Java virtual machine.

The JMS specification defines two types of message sending and receiving models: peer-to-peer queue and publish and subscribe topic. The difference is that they can be consumed repeatedly and whether they are saved or not.

1. Peer-to-peer queue: cannot be consumed repeatedly. Messages are saved until they are consumed.

The producer sends a message to the queue, and a consumer takes out and consumes the message.

After the message is consumed, it is no longer saved in the queue, and only one consumer can retrieve the message.

Queue supports the existence of multiple consumers, but only one consumer can consume a message.

When there is currently no consumer, the message is saved until it is consumed by the consumer.

2. Publish and subscribe topic: can be consumed repeatedly and published to all subscribers.

The producer publishes the message to the topic and multiple subscribers receive and consume the message.

Unlike queue, messages published to topic are consumed by all subscribers.

When a producer publishes a message, the message is not saved, regardless of whether there are subscribers or not.

Comparison between queue and topic, two types of message transport models defined by the JMS specification:

Queue

Topic

Model

Peer-to-peer Point-to-Point

Publish and subscribe publish/subscribe

With or without state

A file in which queue messages are saved on the mq server before consumption or configure DB

Topic data is not saved by default and is stateless.

Integrity guarantee

Queue ensures that every message is received by the consumer

Topic does not guarantee that every message published by the producer will be received by the subscriber.

Whether the message will be lost

The producer sends a message to the queue and the consumer receives the message. If there is no consumer, it will always be saved and will not be lost.

When a producer publishes a message to topic, current subscribers can receive the message. If there are no current subscribers, the message is lost.

Message publishing and receiving strategy

An one-to-one message publishing and receiving strategy in which messages sent by one producer are received by only one consumer. When the mq server receives the reply, it deletes the message.

With an one-to-many message publishing and receiving strategy, multiple subscribers to the same topic can receive messages released by the producer.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report