2. Overview:
Apache ActiveMQ is the most popular and powerful open source messaging and
Integration Patterns server.
Apache ActiveMQ is fast, supports many Cross Language Clients. Using this we can
enable to message throttling, redelivery, delay of messages.
In this Presentation will going to see
ActiveMQ Installation and configurations
DeadLetter queue configuration
Configuring ActiveMQ in clusters
Running ActiveMQ in clusters
3. ActiveMQ Installation and configurations:
Prerequisites
ActiveMQ installer -- apache-activemq-5.8.0-bin.zip
Database:- Microsoft SQL Server
Limitations:
The configuration is done in activemq.xml and the configuration tags used in the
code works with apache-activemq version 5.8.0.It might change according to latest
versions.
4. Steps to Install
Extract apache-activemq-5.8.0-bin.zip to a folder eg:- Applications where it will be
running
It will create the folder apache-activemq-5.8.0 in the Applications folder
Go to the folder <apache-activemq-5.8.0bins> and start the activemq.bat file
The ActiveMq server will be started and will be running.
Enter the address in the browser :- http://localhost:8161/admin
Enter the user name and password as admin , admin
5. DeadLetter queue configuration:
To configure DeadLetter Queue in activeMQ:-
Go to the folder <apache-activemq-5.8.0conf>
Open the file activemq.xml in an editor.
Modify the following in the file :-
Set the following code in the redeliveryPolicyMap:-
<redeliveryPolicyEntries>
<redeliveryPolicy queue=">" maximumRedeliveries="1"
redeliveryDelay="1200000" initialRedeliveryDelay="5000"
useCollisionAvoidance="true" />
</redeliveryPolicyEntries>
Enter the following tags:-
<broker xmlns="http://activemq.apache.org/schema/core"
brokerName="localhost " dataDirectory="${activemq.data}" persistent="true">
6. Here maximumRedeliveries is the number of redeliveries of the messages,
redeliveryDelay is the interval of messages to be delivered and
initialRedeliveryDelay is the interval which the messages will be triggered for the
first time.
Here brokerName needs to be mentioned.
The above script will set the redeliveryPolicies.
Note:-The queue will not be created until messages are pushed in ActiveMQ.
Open Mule and run the consumer program to consume the messages from
ActiveMQ.
Once the data is pushed from SAP the ActiveMQ will create the queue and stores
the messages.
7. Now whenever the consumer throws an exception, The messages will retry to a
certain time based on redelivery policy of ActiveMQ and a deadletter queue will
be created and failed messages will be pushed to the deadletter queue.
8. Configuring ActiveMQ in clusters:
Clustering is needed so that if 1 node(master) goes down then the other
nodes(slaves) can take the work from it and the data should always be available.
Steps to Install and configure ActiveMQ in clusters:-
Let there be 2 nodes which we want to configure in cluster.
Repeat the installing and configuring of ActiveMQ on both systems which would
be in clusters.
Need to install Microsoft SQL Server on one of the systems that are in clusters.
Now open the activemq.xml file of ActiveMQ from <apache-activemq-5.8.0conf>
folder.
Change the broker name.Note:- The broker name should be different for both the
nodes:-
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="Node1 "
dataDirectory="${activemq.data}" persistent="true">
9. Enter the following tag below to bean class tag in the file:-
Add the following tags inside persistenceAdapter tag:-
<bean id="sql-ds"
class="org.apache.commons.dbcp.BasicDataSource" destroy-
method="close">
<property
name="driverClassName"
value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
<property name="url"
value="jdbc:sqlserver://=%ipaddress%SQLEXPRESS:1433;databaseNa
me=SOA_VMES"/>
<property name="username"
value="username"/>
<property name="password"
value="samplepassword"/>
<property name="maxActive"
value="200"/>
<property
name="poolPreparedStatements" value="true"/>
</bean>
<jdbcPersistenceAdapter dataDirectory="${activemq.base}/activemq-data"
dataSource="#sql-ds" useDatabaseLock="true" lockKeepAlivePeriod="5000"/>
10. Remove the kahaDB tag from persistenceAdapter tag.
Copy the sqljdbc4.jar file in activemq lib folder if it is not there.
Give different web app port numbers in different nodes.(For ex :node1->8161 &
node->8162)
Change port number in transportConnector tag in activemq.xml file in node2.
(for ex node1 give 61616 & for node2 give 62626).
Note: - useDatabaseLock="true" should always be true
Here driverClassName is the name of the database driver.
url is the url of the SQL server with the database name.
username and password are the username and password for the database
dataSource is the the name of the data source we are configuring in the database
configuration.
Now go to the next clustered node and open the activemq.xml file of ActiveMQ
from <apache-activemq-5.8.0conf> folder
Repeat the same configuration and both the ActiveMQ are in clustered
11. Note here in this node the broker name need to be changed
Rest everything in the configuration file of the second node will be same as it is.
Note there should be a database named SOA_VMES in the SQL server which the
ActiveMQ will use for clustering.
The database should be one which will be using by both the clusters. The database
should be installed in any one of the node.
<broker xmlns="http://activemq.apache.org/schema/core"
brokerName="Node2 " dataDirectory="${activemq.data}"
persistent="true">
12. Running ActiveMQ in clusters:
Go to node1 which is the first node in the cluster. This node will act as master.
Go to the folder <apache-activemq-5.8.0bins> and start the activemq.bat file
The ActiveMQ node1 server will be started and will act as a Master node
13. Enter the address in the browser :- http://localhost:8161/admin
Enter the user name and password as admin , admin
Click the Queue in the portal to view the queue messages in the ActiveMQ
Currently there will be no messages and following screen will appear
14. Goto node2 and repeat the same process to start activeMQ server
Now both the nodes are running in clusters.
Node2 will start but since Node2 is a slave it will not be activated and wait for the
control of the database due to database lock. Check the screenshots below:-
Node2 ActiveMQ server is waiting for the database lock to be release. If we open
the browser in node2 and enter http://localhost:8162/admin, it will not display
anything since it is not activated.
15. For Testing purpose, push the messages to Master (Node1) server using some Java
code or Mule ESB flows.
Stop the master instance.
Slave instance will pick the lock from database immediately and gets the messages
from Node1
Open the browser http://localhost:8162/admin.
You can able to see messages that has been received from Master node.