JMS Learning (iii) ActiveMQ Message persistence

Source: Internet
Author: User
Tags amq

The 1,JMS specification supports two types of message delivery: Persistent and non-persistent. ACTIVEMQ supports the recovery of messages, intermediate status messages (message is cached in memory) when both types of delivery are supported

2,ACTIVEMQ can store messages in three types of media: file-based (stored in a file), in-memory (stored in memory), relational databases (stored in a relational database)

What is the use of 3,persistence message?

Persistent messages is ideal if you want messages to always being available to a message consumer after they has been deliv Ered to a message broker, or need messages to survive even if there have been a system failure.

① messages are always available to consumers. The message is not lost after the ② system is down.

4,ACTIVEMQ stores two types of destination, the subject (Topic) and the queue. The domain that corresponds to the topic is the Publish-subscribe model (PUB/SUB), and the queue-corresponding domain is a point-to-point model.

Queue Storage : Stores messages in FIFO order, only one message is dispatched between one of potentially many consumers. Only if the message has been consumed and acknowledged can it is deleted from the broker ' s message store.

For many consumers, only one of the consumers can receive the message. The message can only be deleted after the consumer has consumed it.

Topic Storage:

For durable subscribers-a topic, each consumer gets a copy of the message. In order to save space (some messages can being very large!), only one copy of a message was stored by the broker.

What is durable Subscribers (persistent subscriber)? For durable subscribers, although it is currently inactive (not connected to Borker), the message to broker (similar to QQ offline messages) will not be missed. Persistent subscriber maintainer a message pointer that always points to the next message that the subscriber needs.

A durable subscriber object in the store maintains a pointer to their next stored message and dispatches a copy of it to it Consumer as shown in Figure 5.2.

Why do you design this?

① each consumer's consumption rate is different

② not all consumers are online (actived)

③ the same message may be subscribed by multiple consumers

With this form of pointers, it is possible to solve the problems in the above three situations. The message can be removed from the broker only if all consumers have received the message.

How the message is stored in 5,ACTIVEMQ:

ActiveMQ provides a pluggable API for message stores as well as multiple message store implementations including:

①AMQ Message Store

②KAHADB Message store,activemq 5.13. The default storage mode for version 2

③JDBC Message Store

Configuration options for storage in configuration file Activemq.xml:

The idea of AMQ storage is well worth seeing:

The JournaL consists of a rolling log of messages and commands (such as transactional boundaries and message dele tions) stored in data files of a certain length. When the maximum length of the currently used data file have been reached a new data file is created. All of the messages in a data file was reference counted, so, once every message in this data file is no longer required, The data file can be removed or archived. The journal only appends messages to the end of the "Current data file" So storage is very fast.

The file that stores the journal is fixed-length and is written to the file only in Append mode.

For convenience, direct.

KAHADB messages are not stored in the same way. The Amq method uses Hashtable storage reference index, while KAHADB uses B-tree storage index.

In addition, for the configuration of ACTIVEMQ using JDBC as a method of persistent storage, refer to this article

6,broker Caching messages for consumer

As mentioned in the 5th, messages are stored in persistent media and therefore do not apply to situations where real-time messages are required. ---For example, the transaction information needs to be acquired in seconds, and it is no longer needed after the run-time.

So, ACTIVEMQ can configure which types of messages are cached, how many messages are cached, and how long are these messages cached?

Messages that was cached by the broker was only dispatched to a topic consumer if it was retroactive; And never to durable topic subscribers

JMS Learning (iii) ActiveMQ Message persistence

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.