Basic Concepts of ActiveMQ

1 Basic concept
ActiveMQ: It is the most popular and powerful open source message bus produced by Apache. It is a JMS Provider implementation that fully supports the JMS1.1 and J2EE 1.4 specifications.
JMS (Java Message Service): It is an API for message-oriented middleware (MOM) in the Java platform, which is used to send messages between two applications or distributed systems for asynchronous communication.

2 JMS message mode
2.1 Point-to-point or queue mode
  Each message can only have one consumer. There is no temporal correlation between the producer and the consumer of the message, and the consumer can retrieve the message regardless of whether it was running when the producer sent the message.


2.2 Pub/Sub publish/subscribe model
Each message can have multiple consumers. There is a temporal correlation between producers and consumers. A consumer subscribed to a topic can only consume messages published since it subscribed.

3 Broker node
represents a node running MQ.

4. Transport mode
ActiveMQ currently supports the following Transport: VM Transport, TCP Transport, NIO Transport, SSL Transport, Peer Transport, UDP Transport, Multicast Transport, HTTP and HTTPS Transport, WebSockets Transport, Failover Transport, Fanout Transport, Discovery Transport, ZeroConf Transport et al.
1) VM Transport: Allows the client and the Broker to communicate directly within the VM. The connection used is not a Socket connection, but a direct method call, thus avoiding the overhead of network transmission. The application scenario is also limited to the Broker and the client in the same JVM environment.
2) TCP Transport: The client connects to the remote Broker through TCP Socket. Configuration syntax:
tcp://hostname:port?transportOptions
3) HTTP and HTTPS Transport: Allow clients to connect using REST or Ajax. This means that it is possible to send messages to ActiveMQ directly using JavaScript.
4) WebSockets Transport: Allows clients to connect to the Broker through HTML5 standard WebSockets.

5 Persistence Persistence
    Message persistence should be a better method for reliable message delivery. With message persistence, even if the sender and receiver are not online at the same time or the message center goes down after the sender sends the message , the message can still be sent after the message center is restarted. If this persistence and ReliableMessaging are combined, it should be very good to ensure the reliable delivery of the message.
    The principle of message persistence is very simple. After the sender sends the message, the message center first stores the message in a local data file, an in-memory database, or a remote database, etc., and then tries to send the message to the receiver. Delete from storage, or keep trying if it fails. After the message center is started, the designated storage location must be checked first. If there is a message that has not been sent successfully, the message needs to be sent out.

5.1 AMQ Message Store
    AMQ is a form of file storage that is characterized by fast writing and easy recovery. Messages are stored in files. The default size of the file is 32M. If the size of a message exceeds 32M, this value must be set larger. When the messages in a stored file have all been consumed, then the file will be marked as deletable, and in the next cleanup phase, the file will be deleted. AMQ is available for versions prior to ActiveMQ 5.3.
5.2 Kaha Persistence (Persistence as a file)
    KahaDB, a message store based on file-supported transactions, is a reliable, high-performance, and scalable message store. KahaDB is a file-based local database storage form. Although it is not as fast as AMQ, it has strong scalability and a shorter recovery time than AMQ. Since version 5.4, KahaDB has been used as the default persistence method.
The default configuration is as follows:
<persistenceAdapter>
   <kahaDB directory="activemq-data" journalMaxFileLength="32mb"/>
</persistenceAdapter>

// MessageProducer: message sender
MessageProducer producer;
// The setting is not persistent, it is actually decided according to the project  
// PERSISTENT: Save to disk. After the consumer consumes, the message is deleted.  
// NON_PERSISTENT: Save to memory, message is cleared after consumption.  
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);  
// Note: Too many messages can cause memory overflow.

Restart MQ after downtime:


5.3 JDBC Persistence (persistent as database)
can store messages in databases, such as MySQL, SQL Server, Oracle, DB2.

Configure the JDBC adapter:
<persistenceAdapter>
    <jdbcPersistenceAdapter dataSource="#mysql-ds" createTablesOnStartup="false" />
</persistenceAdapter>

Persist data into MySQL.

  5.3.1 First download the mysql-connector-java-5.*.*-bin.jar package from http://dev.mysql.com/downloads/connector/j/ and put it in:
D:\software\apache-activemq- 5.14.2\lib directory.


  5.3.2 apache-activemq-5.14.2\conf\activemq.xml configure
persistence mode:
<!--
<persistenceAdapter>
            <kahaDB directory="${activemq.data}/kahadb"/>
        </persistenceAdapter>
        -->
	<persistenceAdapter>  
            <jdbcPersistenceAdapter  dataDirectory="${activemq.base}/data" dataSource="#mysql-ds" useDatabaseLock="false"/>   
        </persistenceAdapter>


  Data source:
put it outside the broker tag
<!-- MySQL DataSource -->  
	<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:3306/activemq?relaxAutoCommit=true"/>  
        <property name="username" value="root"/>  
        <property name="password" value="123456"/>   
        <property name="poolPreparedStatements" value="true"/>   
    </bean>


Three tables of persistent mysql database are automatically created after startup:
activemq_acks: ActiveMQ sign-in information.
activemq_lock: ActiveMQ lock information.
activemq_msgs: ActiveMQ message information For

specific documents, see http://572327713.iteye.com/blog/2347874

5.4 LevelDB Persistence
This file system was introduced after ActiveMQ5.8, it is very similar to KahaDB, and it is also a file-based local A form of database storage, but it provides faster persistence than KahaDB. Unlike KahaDB, it does not use traditional B-trees to achieve write-ahead of log data, but uses index-based LevelDB.
The default configuration is as follows:
<persistenceAdapter>
      <levelDBdirectory="activemq-data"/>
</persistenceAdapter>

http://blog.csdn.net/kobejayandy/article/details/50736479
http://blog.csdn.net/boonya/article/details/51259068




Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326856429&siteId=291194637