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

ActiveMQ (09): ActiveMQ message store persistence

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

I. brief introduction

1.1 description

ActiveMQ not only supports persistent and non-persistent, but also supports message recovery (recovery), re-delivery, etc.

1.2 PTP and PUB/SUB

1.2.1 PTP

For persistent subscription topics, each consumer will get a copy of the message.

1.2.2 PUB/SUB

For persistent subscription topics, each consumer will get a copy of the message.

1.3 valid message storage

ActiveMQ provides a plug-in message storage, which is similar to the multipoint propagation of messages. It mainly implements the following:

1:AMQ message Store-File-based storage, which was previously the default message store

2:KahaDB message storage-provides capacity enhancement and resilience and is now the default storage method

3:JDBC message store-messages are stored based on JDBC

4:Memory message store-memory-based message store

II. Persistence

2.1 KahaDB message Store

1. KahaDB is the default storage method, which can be used in any scenario to improve performance and resilience. The message store uses a transaction log and only one index file to store all its addresses.

You can view it in: activemq/conf/activemq.xml

2. KahaDB is a solution for message persistence, which optimizes the typical message usage pattern. In Kaha, the data is appended to the data logs. When log text is no longer needed

The log file is discarded when the data in the.

3. Example of basic configuration of KahaDB:

The available properties are:

The path where 1:director:KahaDB is stored. Default is activemq-data.

2:indexWriteBatchSize: the number of index page written to disk in bulk. Default is 1000.

3:indexCacheSize: number of cached index page in memory. Default is 10000.

4:enableIndexWriteAsync: whether to write the index asynchronously. Default is false.

5:journalMaxFileLength: sets the size of each message data log. The default is 32MB.

6:enableJournalDiskSyncs: sets whether to ensure that every content without transaction is written to disk synchronously, which is required when JMS is persisted. Default is true.

7:cleanupInterval: after checking a message that is no longer in use, the time before deleting the message is 30000 by default.

Interval between 8:checkpointInterval:checkpoint. Default is 5000.

9:ignoreMissingJournalfiles: whether to ignore lost message log files, default false

10:checkForCorruptJournalFiles: upon startup, the message file will be verified for corruption. Default is false.

11:checksumJournalFiles: whether to provide checksum for each message log file, default false

12:archiveDataLogs: whether to move files to a specific path instead of deleting them, default false

13:directoryArchive: defines the path to which the data log is moved after the message has been consumed. Default is null.

14:databaseLockedWaitDelay: the wait time to get the database lock (used by shared master/slave). Default is 10000.

15:maxAsyncJobs: sets the maximum asynchronous message queue that can be stored. The default value is 10000, which can be set to the same value as concurrentMessageProducers.

16:concurrentStoreAndDispatchTransactions: whether to distribute the message to the client, while the transaction stores the message. Default true

17:concurrentStoreAndDispatchTopics: whether to distribute Topic messages to the client and store them at the same time. Default true

18:concurrentStoreAndDispatchQueues: whether to distribute queue messages to the client and store them at the same time. Default true

2.2 AMQ message Store

1. AMQ Message Store is the default persistent storage of ActiveMQ5.0. It is a structure designed for fast message storage based on file and transaction storage, which is in the form of streams.

For message exchange.

2. In this way, Messages is saved to data logs and indexed by reference store to improve access speed. Date logs consists of a number of separate data log files, the default

The file size is 32m, and if the size of a message exceeds the size of the data log file, you can modify the configuration to increase the size of the data log file. If all the deletions in a data log file

If the information is successfully consumed, the data log file will be marked so that it can be deleted or archived in the next round of cleanup.

3. Configuration example

2.3 JDBC message Store

ActiveMQ supports using JDBC to persist messages

2.3.1 predefined tables

1: message table. Both ACTIVEMQ_MSGS,queue and topic are stored in the default table, and the structure is as follows:

The 2:ACTIVEMQ_ACKS table stores the information of the persistent subscription and the message ID received by the last persistent subscription, which is structured as follows:

3: lock the table. The default table name is ACTIVEMQ_LOCK, which is used to ensure that only one ActiveMQ broker instance can access the database at a certain time. The structure is as follows:

2.3.2 configure activemq/conf/activemq.xml

.

Note: here you need to upload the database driver package to / opt/activemq/lib. I use Ali's connection pool here, so I also upload the druid package.

Restart activemq

The test sends 3 queue messages:

Supplement: JDBC Message Store with ActiveMQ Journal

This method overcomes the shortcomings of JDBC Store, uses fast cache write technology, and greatly improves the performance. Configure to comment out persistenceAdapter and then add persistenceFactory. The example is as follows:

The difference between JDBC Store and JDBC Message Store with ActiveMQ Journal:

The performance of 1:Jdbc with journal is better than jdbc.

2:Jdbc is used for database sharing of master/slave schema

3:Jdbc with journal cannot be used in master/slave mode

4: in general, jdbc with journal is recommended.

2.4 Memory message Store

The main purpose of memory message storage is to store all persistent messages in memory. There is no dynamic cache, so you must be careful to set the JVM and memory limits where your broker is located.

Example configuration:

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

Database

Wechat

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

12
Report