It programmer development Essentials-all kinds of resources download list, history of the most IT resources, personal collection summary.
ACTIVEMQ Persistence
Message persistence should be a good way for reliable messaging, with message persistence, even if the sender and recipient are not at the same time online or the message center is down after the sender has sent the message and can still send the message after the message center restarts. If this persistence and reliablemessaging combination should be good to ensure the reliable transmission of the message.
The principle of message persistence is simple, that is, after the sender sends the message, the message center first stores the message to a local data file, a memory database, or a remote database, and then attempts to send the message to the receiver, the message is deleted from the store, and the failure continues to attempt. After the message center is started, first check the established storage location, if you have not sent a successful message, you need to send the message.
ACTIVEMQ Persistence mode: AMQ, kahadb, JDBC, LevelDB.
1, AMQ
AMQ is a form of file storage that has the characteristics of fast writing and easy recovery. The message is stored in a file, the default size of the file is 32M, and if the size of a message exceeds 32M, the value must be set larger. When a message in a stored file has all been consumed, then the file is identified as removable and the file is deleted during the next purge phase. AMQ applies to versions prior to ActiveMQ5.3 . The default configuration is as follows: [HTML] view plain copy print? <persistenceAdapter> <amqpersistenceadapter directory= "Activemq-data" maxfilelength= "32MB"/> </ Persistenceadapter>
The properties are as follows:
Property name |
Default Value |
Description |
Directory |
Activemq-data |
Storage directory for message files and logs |
Usenio |
True |
Storing messages using the NIO protocol |
Synconwrite |
False |
Write to disk synchronously, this option has a very big impact on performance |
Maxfilelength |
32Mb |
The size of a message file |
Persistentindex |
True |
Persistence of the message index, if False, the index is saved in memory |
Maxcheckpointmessageaddsize |
4kb |
Maximum number of messages allowed for a transaction |
CleanupInterval |
30000 |
Clear operation period, Unit MS |
Indexbinsize |
1024 |
Index file Cache page number, the default is 1024, when the AMQ expansion or reduction of storage, will lock the entire broker, resulting in a certain amount of time blocking, so this value should be adjusted to larger, but the code implementation will dynamically scale, the adjustment effect is not ideal. |
Indexkeysize |
96 |
Index key size, key is the message ID |
Indexpagesize |
16kb |
Page size of the index |
Directoryarchive |
Archive |
Store the archived message file directory |
Archivedatalogs |
False |
When true, archived message files are moved to directoryarchive instead of being deleted directly |
2, Kahadb
KAHADB is a file-based local database storage format, although not amq fast, but it has strong extensibility, recovery time is shorter than AMQ, since the 5.4 version of KAHADB as the default persistence mode. The default configuration is as follows: [HTML] view plain copy print? <persistenceAdapter> <kahadb directory= "Activemq-data" journalmaxfilelength= "32MB"/> </ Persistenceadapter>
The properties of the kahadb are as follows:
Property name |
Default Value |
Description |
Directory |
Activemq-data |
Storage directory for message files and logs |
Indexwritebatchsize |
1000 |
The size of a batch of indexes that are updated to the message file when the index amount to be updated reaches this value |
Indexcachesize |
10000 |
In-memory, indexed page size |
Enableindexwriteasync |
False |
Whether the index is asynchronously written to the message file |
Journalmaxfilelength |
32mb |
The size of a message file |
Enablejournaldisksyncs |
True |
Whether non-transactional messages are written to disk synchronously |
CleanupInterval |
30000 |
Clear operation period, Unit MS |
Checkpointinterval |
5000 |
The period in which the index is written to the message file, in units of MS |
Ignoremissingjournalfiles |
False |
Ignore missing message file, False, start exception when message file is lost |
Checkforcorruptjournalfiles |
False |
Check that the message file is corrupt, true, check for corruption and try to fix |
Checksumjournalfiles |
False |
Generates a checksum to be able to detect if the journal file is corrupted. |
Properties that are valid after version 5.4: |
|
|
Archivedatalogs |
False |
When true, archived message files are moved to directoryarchive instead of being deleted directly |
Directoryarchive |
Null |
Store the archived message file directory |
Databaselockedwaitdelay |
10000 |
Delay in waiting for file lock when using load, unit ms |
Maxasyncjobs |
10000 |
The same producer produces the largest number of asynchronous messages waiting to be written |
Concurrentstoreanddispatchtopics |
False |
Whether to forward a topic message when writing a message |
Concurrentstoreanddispatchqueues |
True |
Whether the queue message is forwarded when the message is written |
Properties that are valid after version 5.6: |
|
|
Archivecorruptedindex |
False |
Whether to archive the wrong index |
Each instance of KAHADB can be configured with a separate adapter, and if no destination queue is submitted to filteredkahadb, it means that all queues are valid. If a queue does not have a corresponding adapter, an exception will be thrown. The configuration is as follows:[HTML] View Plain copy print? <persistenceAdapter> <mkahadbdirectorymkahadbdirectory= "${activemq.base}/data/ Kahadb "> <filteredPersistenceAdapters> <!-- match all queues --> <filteredkahadbqueuefilteredkahadbqueue= ">" > <persistenceAdapter> <kahadbjournalmaxfilelengthkahadbjournalmaxfilelength= "32MB"/> </persistenceAdapter> </ filteredkahadb> <!-- match all destinations --> <filteredkahadb> < persistenceadapter> < Kahadbenablejournaldisksyncskahadbenablejournaldisksyncs= "false"/> </persistenceAdapter> </ filteredkahadb> </filteredPersistenceAdapters> </mKahaDB> </persistenceAdapter>
If the Perdestination property of FILTEREDKAHADB is set to true, then the matching target queue will get its own corresponding KAHADB instance. The configuration is as follows:[HTML] View Plain copy print? <persistenceAdapter> <mkahadbdirectorymkahadbdirectory= "${activemq.base}/data/ Kahadb "> <filteredPersistenceAdapters> <!-- kahaDB per destinations --> <filteredkahadb perdestination= "true" > <persistenceAdapter> <kahadbjournalmaxfilelengthkahadbjournalmaxfilelength= "32MB" /> </persistenceAdapter> </filteredKahaDB> </filteredPersistenceAdapters> </mKahaDB> </persistenceAdapter>
3. JDBC
Messages can be stored in a database, such as Mysql, SQL Server, Oracle, DB2.
Configure the JDBC adapter: [HTML] view plain copy print? <persistenceAdapter> <jdbcpersistenceadapterdatasourcejdbcpersistenceadapterdatasource= "#mysql-ds" Createtablesonstartup= "false"/> </persistenceAdapter>
DataSource Specifies whether the bean,createtablesonstartup of the persisted database creates a data table at startup, and the default value is true, so that every boot will create a data table, typically set to true the first time it is started, It is then changed to false.[HTML] View Plain copy print? MySQL persistence bean: <bean id= "Mysql-ds" class= "Org.apache.commons.dbcp.BasicDataSource" destroy-method= "Close" > <property name= "Driverclassname" value= "Com.mysql.jdbc.Driver"/> <property name= "url" Value= "Jdbc:mysql://localhost/activemq?relaxautocommit=true"/> < Property name= "username" value= "activemq"/> <property Name= "Password" value= "activemq"/> <property name= " Poolpreparedstatements " value=" true "/> </bean> Sql server persisted bean: <bean id= "Mssql-ds" class= "Net.sourceforge.jtds.jdbcx.JtdsDataSource" Destroy-method= "Close" > <property name= "ServerName" value= " SERVERNAME "/> <property name= "PortNumber" value= "PortNumber"/> <property name= "DatabaseName" value= "DatabaseName"/> <property name= "User" value= "user"/> <property name = "Password" value= "password"/> </bean> Oracle Persistence bean: <bean id= "Oracle-ds" class= "Org.apache.commons.dbcp.BasicDataSource" destroy-method= "Close" > <property name= "Driverclassname" value= " Oracle.jdbc.driver.OracleDriver "/> <property name=" url " Value= "Jdbc:oracle:thin:@10.53.132.47:1521:activemq"/> <property name= "username" value= "activemq"/> <property name= " Password " value=" ACTIVEMQ "/> <property name= "maxactive" value= "/> " <property name= "Poolpreparedstatements" value= "true"/> </bean > DB2 Persistent bean: <bean id= "Db2-ds" class= " Org.apache.commons.dbcp.BasicDataSource " destroy-method=" Close "> <property name= "Driverclassname" value= "Com.ibm.db2.jcc.DB2Driver"/> <property name= "url" value= "jdbc:db2:// Hndb02.bf.ctc.com:50002/activemq "/> <property name=" Username " value=" activemq "/> <property name=" Password " value=" Activemq "/> <property name=