ActiveMQ Pits Kee

Source: Internet
Author: User
Tags connection pooling message queue mysql view rabbitmq
Objective

MQ is an essential middleware in today's large-scale system architecture, with the previous article, "MQ (Message Queuing) Common scenario Resolution" introduced MQ scenarios, and now several of the popular MQ are Rabbitmq,rocketma,kafka, These MQ is the most easy to find related articles, but also some systems use ACTIVEMQ, because ACTIVEMQ is relatively traditional MQ, in the use of the process will still encounter a lot of pits, here is a brief list of some of the problems you may encounter, Share your experience of using ACITVEMQ with others.

Mysql Persistence

Now everyone uses MQ, basically will persist the data, MQ default storage persisted data use KAHADB, but because everyone is familiar with MySQL, many people will choose MySQL for data persistence, because MySQL view data is more convenient. If you need to change the persistence mode to MySQL, you need to modify the following configuration:

 <persistenceAdapter>            <jdbcPersistenceAdapter dataDirectory="${activemq.data}" dataSource="#mysql-ds" createTablesOnStartup="false" useDatabaseLock="false"/>            <!-- 下面是默认的kahaDB方式,注释掉 -->        <!-- <kahaDB directory="${activemq.data}/kahadb"/> -->        </persistenceAdapter>

There are several places where you need to be concerned about the configuration:

Configuration Description
DataDirectory Requires datadirectory consistency of configuration and broker
DataSource The selection of the data source, the specific configuration of the associated database, the following will specify
Usedatabaselock Whether to use database locks, mainly when the program starts to synchronize query data, resulting in a database lock

Also need to configure the database connection, account number, password, etc.:

 <!-- MySql DataSource  Setup -->    <bean id="mysql-ds" class="org.apache.commons.dbcp2.BasicDataSource" destroy-method="close">        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>        <property name="url" value="jdbc:mysql://0.0.0.0:3306/activemq?relaxAutoCommit=true"/>        <property name="username" value="root"/>        <property name="password" value="******"/>        <property name="poolPreparedStatements" value="true"/>    </bean>

Where the ID name and the datasource mentioned above should be the same. Otherwise, you do not know which instance to connect to.

Database connection Pooling Issues

Start ACTIVEMQ If you are prompted for a database connection pool problem, which may be less lib, increase

    • Mysql-connector-java-5.1.30.jar
    • Commons-dbcp2-2.1.1.jar
    • Commons-pool2-2.4.2.jar

Three packages, put in the Lib directory

Admin interface cannot be opened

If it starts normally, but the management interface does not start, you need to modify the database connection under the management interface.

One of the main reasons for using MQ is that MQ performance is better than traditional relational database performance, but MySQL is not a good choice for storing MQ data, but it is highly recommended not to do so in the opposite direction. Use the default storage method to ensure that performance is the primary feature.

ACTIVEMQ Expiration Configuration

Previously said, ACTIVEMQ performance is not optimal, especially the use of MySQL as a database storage tool, performance is more unreliable, so performance optimization, is an important work, regular cleanup of MQ expiration information, it is very important.

Regular cleanup of invalid queues

The configuration is as follows:

  <destinationPolicy> <policyMap> <policyEntries> <policyentry queue= ">" gcinactivedestinations= "true" inactivetimoutbeforegc= "10000" > <dea                Dletterstrategy> <shareddeadletterstrategy processexpired= "true" expiration= "30000"/> </deadLetterStrategy> </policyEntry> <policyentry topic= ">" Gcinac Tivedestinations= "true" inactivetimoutbeforegc= "10000" > <pendingmessagelimitstr ategy> <constantpendingmessagelimitstrategy limit= "" "/> </pendingmessag elimitstrategy> </policyEntry> </policyEntries> </p Olicymap> </destinationpolicy>  

Regular automatic cleanup of invalid topic and queue, this configuration will only clear the set of time, not be subscribed, while the queue does not have the remaining data.
Also, for Boker nodes, you need to set the Scheduleperiodfordestinationpurge parameter, which indicates how long to perform a test.

 <broker xmlns="http://activemq.apache.org/schema/core" brokerName="localhost01" dataDirectory="${activemq.data}"     useJmx="true" schedulePeriodForDestinationPurge="5000">
Set the global expiration time for a message

Development, you should all know that you can set the expiration time of the message, whether there is a unified set message expiration time?
Add the following configuration under the broker node:

  <plugins>          <!-- 86400000 为一天,设置为10天过期 -->            <timeStampingBrokerPlugin ttlCeiling="10000"            zeroExpirationOverride="10000" />        </plugins>

In order to facilitate testing, I set the 10s, of course, the production environment according to their own is actually set will be relatively long. Expired time will enter dead letter, dead letter will also follow this time, after the expiration, the system will automatically delete the information.
After my personal experience, MQ accumulated data up to tens, the performance degradation of the more severe, regular cleanup of MQ messages, is an important operation to optimize performance.

Summarize

Today, the choice of MQ is many, it is recommended to choose RABBITMQ, ROCKETMQ or Kafka, if you have chosen Activemq, need to pay constant attention to the consumption of MQ, it is best to set the expiration time, regularly clean up the message queue data, to avoid the accumulation of data, Cause a decrease in performance.

Number: Itmifen

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.