ActiveMQ 5.x
- How does ActiveMQ work ?
ActiveMQ sends message between client application - producers
Consumers sẽ là recived and process massage. The ActiveMQ broker router each message throught one of two type of destinations:
- a queue : point-to-point
- topic : publish/subscribe
- Memory and Storage
A. Memory
ActiveMQ uses memory to store messages awaiting dispatch to consumers.
ActiveMQ also writes messages to disk, in either a message store (where persistent messages go), or a temp store (where non-persistent messages go when the broker runs out of memory to store them).
JMS is the communication standard that ActiveMQ uses to send and receive messages. ActiveMQ is a JMS provider, which means that it implements the functionality specified in the JMS API. Client applications—producers and consumers—use the JMS API to send and receive messages.
Gía trị cursorMemoryHighWaterMark tức là khi đến % của giá trị memoryLimit thì dữ liệu sẽ tự động đẩy xuống disk
- ActiveMQ message store :
Configuration
To use KahaDB as the broker’s persistence adapter configure ActiveMQ as follows (example):
- Cấu truc directory của KahaDB trên local server:
- db.data:This file contains the persistent BTree indexes to the messages held in the message
data logs.
- db.redo: This is the redo file, used for recovering the BTree indexes if the KahaDB message store starts after a hard stop
- db.log : This exists only if archiving is enabled. The archive is used to store data logs that are no longer needed by KahaDB, making it possible to replay messages from the archived data logs at a later point. If archiving isn’t enabled (the default), data logs that are no longer in use are deleted
from the file system.
ActiveMQ sends message between client application - producers
Consumers sẽ là recived and process massage. The ActiveMQ broker router each message throught one of two type of destinations:
- a queue : point-to-point
- topic : publish/subscribe
- Memory and Storage
A. Memory
ActiveMQ uses memory to store messages awaiting dispatch to consumers.
ActiveMQ also writes messages to disk, in either a message store (where persistent messages go), or a temp store (where non-persistent messages go when the broker runs out of memory to store them).
Có 2 cách thức gửi message : persistent và non-persistent
non-persistent
: Each non-persistent message is stored in memory as it arrives. When the
available memory is full, all messages in memory are moved to the temp store on
the disk. Nếu service stop thì mất tất cả dữ liệu
( Lưu trong memory , nếu memory không còn thì sẽ thực hiện ghi xuống temporary file.)
persistent:
Each persistent message is also stored in memory as it arrives, and is also
written to the message store on disk (KahaDB). If no more memory is available, incoming
persistent messages are written directly into the message store. Sẽ không mất
dữ liệu khi bi stop
Mặc đinh thì ActiveMQ statup script tell Java to create a heap with maximum size là 1GB (-Xmx).
Gía trị -Xmx là giá trị memory JMS . để cấu hình memory limit thì có 2 cách
c1. Cấu hình sử dụng memoryUsage
...]
<systemUsage>
<systemUsage>
<memoryUsage>
<memoryUsage limit="1 gb" />
</memoryUsage>
</systemUsage>
</systemUsage>
[...]
</broker>
c2. Cấu hình sử dụng percentOfJvmHeap
[...]
<systemUsage>
<systemUsage>
<memoryUsage>
<memoryUsage percentOfJvmHeap="60" />
</memoryUsage>
</systemUsage>
</systemUsage>
[...]
</broker>
Gía trị cursorMemoryHighWaterMark tức là khi đến % của giá trị memoryLimit thì dữ liệu sẽ tự động đẩy xuống disk
memoryLimit
|
n/a
|
The memory limit (in bytes) of the
destination’s cursor. This memory limit is subordinate to the system level
memory limit, as specified by the <systemUsage>/<memoryUsage> attribute. There is no default for this value; it simply
acts as a child to the overall broker memory until the broker memory is
exhausted. Note: when this limit is specified the
destination’s cursorMemoryHighWaterMark will be applied against it and not the <systemUsage>/><memoryUsage> memory limit.
|
cursorMemoryHighWaterMark
|
70
|
The percentage (%) threshold applied either
to the <systemUsage>/<memoryUsage> or the destination’s memoryLimit (when
defined) which when exceeded will cause the
destination’s cursor to either block or write to disk.
|
tham khảo:
B. Storage
You can specify the amount of storage to be used for persistent messages in the activemq.xml file’s storeUsage element, as in the example below:<systemUsage>
<systemUsage>
<storeUsage>
<storeUsage limit="100 mb"/>
</storeUsage>
</systemUsage>
</systemUsage>
Storage for non-persistent messages is specified separately. Non-persistent messages are written to storage only after available memory is exhausted. You can specify the amount of storage to be used for non-persistent messages in the activemq.xml file’s tempUsage element, which defaults to 50 GB. You can configure this as a percentage of available disk space (percentLimit) or as a number of bytes (as shown below):<systemUsage>
<systemUsage>
<tempUsage>
<tempUsage limit="100 mb"/>
</tempUsage>
</systemUsage>
</systemUsage>
- KahaDB message store
- AMQ message store
- JDBC message store
- Memory message store
KahaDB is a file based persistence database that is local to the message broker that is using it. It has been optimized for fast persistence. It is the the default storage mechanism since ActiveMQ 5.4. KahaDB uses less file descriptors and provides faster recovery than its predecessor, the AMQ Message Store.
Configuration
To use KahaDB as the broker’s persistence adapter configure ActiveMQ as follows (example):
<broker brokerName="broker">
<persistenceAdapter>
<kahaDB directory="activemq-data" journalMaxFileLength="32mb"/>
</persistenceAdapter>
</broker>
- db.data:This file contains the persistent BTree indexes to the messages held in the message
data logs.
- db.redo: This is the redo file, used for recovering the BTree indexes if the KahaDB message store starts after a hard stop
- db.log : This exists only if archiving is enabled. The archive is used to store data logs that are no longer needed by KahaDB, making it possible to replay messages from the archived data logs at a later point. If archiving isn’t enabled (the default), data logs that are no longer in use are deleted
from the file system.
- Cấu hình monitor cho activeMQ sử dụng Hawtio
1. Insert Hawtio
- wget -c https://oss.sonatype.org/content/repositories/public/io/hawt/hawtio-default/2.3.0/hawtio-default-2.3.0.war
- unzip hawtio-default-2.3.0.war -d hawtio
- mv hawtio <PATH_TO_ACTIVEMQ_INSTALLATION>/webapps
Hawtio, edit jetty.xml in the conf/ subdirectory under your ActiveMQ installation directory to add Hawtio as a web component of your ActiveMQ installation. Find the <ref bean="rewriteHandler"/> tag and add this block immediately after it:
Hawtio installation with a secure password, edit the conf/users.properties file. Locate the line that reads:
activemq-performance-tuning
Using ActiveMQ – “Master/Slave” configuration with failover protocol
1. Insert Hawtio
- wget -c https://oss.sonatype.org/content/repositories/public/io/hawt/hawtio-default/2.3.0/hawtio-default-2.3.0.war
- unzip hawtio-default-2.3.0.war -d hawtio
- mv hawtio <PATH_TO_ACTIVEMQ_INSTALLATION>/webapps
Then, edit the env file in the bin
directory of your ActiveMQ installation. Add the following line at the end of
the file:
ACTIVEMQ_OPTS="$ACTIVEMQ_OPTS -Dhawtio.realm=activemq
-Dhawtio.role=admins
-Dhawtio.rolePrincipalClasses=org.apache.activemq.jaas.GroupPrincipal"
|
Hawtio, edit jetty.xml in the conf/ subdirectory under your ActiveMQ installation directory to add Hawtio as a web component of your ActiveMQ installation. Find the <ref bean="rewriteHandler"/> tag and add this block immediately after it:
<bean class="org.eclipse.jetty.webapp.WebAppContext">
<property name="contextPath" value="/hawtio" />
<property name="resourceBase"
value="${activemq.home}/webapps/hawtio" />
<property name="logUrlOnStart" value="true" />
</bean>
|
Hawtio installation with a secure password, edit the conf/users.properties file. Locate the line that reads:
admin=admin
Edit it by specifying your desired
password:
admin=<MY_NEW_PASSWORD>
Restart ActiveMQ and browse to
http://<YOUR_ACTIVEMQ_HOST_IP>:8161/hawtio. You can now log in with the
username admin and the password <MY_NEW_PASSWORD>.
activemq-performance-tuning
Using ActiveMQ – “Master/Slave” configuration with failover protocol


Nhận xét
Đăng nhận xét