This topic describes how to connect to ActiveMQ Artemis using ClientConnect mode through JNDI to achieve fault tolerance and high availability.

Fault tolerance and high availability can be achieved by creating an ActiveMQ Artemis cluster. Fault tolerance refers to creating redundancy in terms of software, so this example involves creating a cluster of ActiveMQ Artemis brokers. High availability refers to ensuring hardware doesn't fail. To achieve high availability, create the ActiveMQ Artemis brokers on different machines.

Prerequisites

This topic assumes you have the ActiveMQ Artemis binaries, and that the Progress OpenEdge JMS Adapter is installed and configured on your machine.

Main steps

To achieve a fault-tolerant, highly available ActiveMQ Artemis cluster configuration, follow these steps:
  1. Navigate to the location where you want to create ActiveMQ Artemis master and worker brokers. For example: C:\JMS\ArtemisMQ.
  2. Run the following artemis create commands to create master and worker brokers. For example:
    C:\JMS\ArtemisMQ>apache-artemis-2.11.0-bin\apache-artemis-2.11.0\bin\artemis create master --http-port 8162 --default-port 81617
    
    C:\JMS\ArtemisMQ>apache-artemis-2.11.0-bin\apache-artemis-2.11.0\bin\artemis create worker --http-port 8163 --default-port 81618
    Note: Because the above commands create ActiveMQ Artemis brokers on localhost, provide admin/admin for username and password, and 'N' for anonymous access. To achieve high availability, create these brokers on different machines.

    These commands create master and worker directories in the location where they were run.

  3. In the master\etc directory, open the broker.xml file and locate the <acceptors> tag.
  4. Remove all content between the <acceptors> opening and closing tag, including the <acceptors> tags themselves. Replace that content with the following information:
    	<connectors>
    		<connector name="artemis">tcp://localhost:61617</connector> 
    	</connectors>
    
    	<ha-policy>
    		<replication>
    			<master>
    			<check-for-live-server>true</check-for-live-server>
    			</master>
    		</replication>   
    	</ha-policy>
    
    	<acceptors>
    		<acceptor name="artemis">tcp://localhost:61617</acceptor>
    	</acceptors>
    	
    	<cluster-user>cluster</cluster-user>
    	<cluster-password>cluster</cluster-password>
    	
    	<broadcast-groups>
    		<broadcast-group name="bg-group1">
    			<group-address>231.7.7.7</group-address>
    			<group-port>9876</group-port>
    			<broadcast-period>5000</broadcast-period>
    			<connector-ref>artemis</connector-ref>
    		</broadcast-group>
    	</broadcast-groups>
    	<discovery-groups>
    		<discovery-group name="dg-group1">
    			<group-address>231.7.7.7</group-address>
    			<group-port>9876</group-port>
    			<refresh-timeout>10000</refresh-timeout>
    		</discovery-group>
    	</discovery-groups>
    	
    	<cluster-connections>
    		<cluster-connection name="my-cluster">
    			<connector-ref>artemis</connector-ref>
    			<message-load-balancing>ON_DEMAND</message-load-balancing>
    			<max-hops>0</max-hops>
    			<discovery-group-ref discovery-group-name="dg-group1"/>
    		</cluster-connection>
    	</cluster-connections>
    
  5. In the worker\etc directory, open the broker.xml file and locate the <acceptors> tag.
  6. Remove all content between the <acceptors> opening and closing tag, including the <acceptors> tags themselves. Replace that content with the following information:
    	<ha-policy>
    		<replication>
    			<slave>
    				<allow-failback>true</allow-failback>
    				<failback-delay>5000</failback-delay>
    			</slave>
    		</replication>
    	</ha-policy>
    
    	<connectors>
    		<connector name="artemis">tcp://localhost:61618</connector>
    		<connector name="netty-live-connector">tcp://localhost:61617</connector>
    	</connectors>
    
    	<acceptors>
    		<acceptor name="artemis">tcp://localhost:61618 </acceptor>
    	</acceptors>
    	
    	<cluster-user>cluster</cluster-user>
    	<cluster-password>cluster</cluster-password>
    	
    	<broadcast-groups>
    		<broadcast-group name="bg-group1">
    			<group-address>231.7.7.7</group-address>
    			<group-port>9876</group-port>
    			<broadcast-period>5000</broadcast-period>
    			<connector-ref>artemis</connector-ref>
    		</broadcast-group>
    	</broadcast-groups>
    	<discovery-groups>
    		<discovery-group name="dg-group1">
    			<group-address>231.7.7.7</group-address>
    			<group-port>9876</group-port>
    			<refresh-timeout>10000</refresh-timeout>
    		</discovery-group>
    	</discovery-groups>
    	
    	<cluster-connections>
    		<cluster-connection name="my-cluster">
    			<connector-ref>artemis</connector-ref>
    			<message-load-balancing>ON_DEMAND</message-load-balancing>
    			<max-hops>0</max-hops>
    			<discovery-group-ref discovery-group-name="dg-group1"/>
    		</cluster-connection>
    	</cluster-connections>
    
  7. Navigate to the master\bin directory and run the following command:
    C:\JMS\ArtemisMQ\master\bin>artemis run
  8. In a new terminal window, navigate to the worker\bin directory and run the following command:
    C:\JMS\ArtemisMQ\worker\bin>artemis run
    When you see the “backup announced” text in the worker console that means the cluster connection was created.
  9. In the C:\JMS\ArtemisMQ directory, create an AdminObjectFinder.Java and a jndi.properties file. Code for creating the AdminObjectFinder.java and jndi.properties files for ActiveMQ Artemis can be found in the AdminObjectFinder.java and jndi.properties example for ActiveMQ Artemis topic.
  10. Copy the artemis-jms-client-all-version.jar file into the C:\JMS\ArtemisMQ directory. For example:
    C:\JMS\ArtemisMQ>copy apache-artemis-2.11.0-bin\apache-artemis-2.11.0\lib\client\artemis-jms-client-all-2.11.0.jar .
  11. Run the following command to compile the AdminObjectFinder.java file and generate a jmsfromABL package:
    C:\JMS\ArtemisMQ>javac -cp artemis-jms-client-all-2.11.0.jar;.; -d . AdminObjectFinder.java
  12. Run the following command to generate an AdminObjectFinder.jar file:
    C:\JMS\ArtemisMQ>jar -cvf AdminObjectFinder.jar jmsfromABL jndi.properties
  13. Add the AdminObjectFinder.jar file to the classpath in $DLC/properties/JavaTools.properties along with the ActiveMQ Artemis client jars. For example:
    [SonicMQ]
    classpath=C:\JMS\ArtemisMQ\AdminObjectFinder.jar,C:\JMS\ArtemisMQ\apache-artemis-2.11.0-bin\apache-artemis-2.11.0\lib\client\artemis-jms-client-all-2.11.0.jar,C:\JMS\ArtemisMQ\apache-artemis-2.11.0-bin\apache-artemis-2.11.0\lib\slf4j-api-1.7.21.jar,C:\JMS\ArtemisMQ\apache-artemis-2.11.0-bin\apache-artemis-2.11.0\lib\activemq-client-5.14.5.jar,C:\JMS\ArtemisMQ\apache-artemis-2.11.0-bin\apache-artemis-2.11.0\lib\hawtbuf-1.11.jar,${DLC}/java/progress.jar,${DLC}/java/ext/geronimo-j2ee-management_1.1_spec-1.0.1.jar
    jvmargs=-DsonicMQExtensions=false -DjmsProvider=ArtemisMQ
  14. Create and run the following Producer_JNDI.p file in prowin:
    DEFINE VARIABLE ptpsession AS HANDLE.
    DEFINE VARIABLE messageH AS HANDLE.
    DEFINE VARIABLE lDebug AS LOGICAL.
    DEFINE VARIABLE cdate AS CHARACTER NO-UNDO FORMAT "x(16)".
    DEFINE VARIABLE ddate AS DATE      NO-UNDO.
    
    
    /* Creates a session object. */
    RUN jms/ptpsession.p PERSISTENT SET ptpsession ("-SMQConnect").
    
    /* Set user credentials. */
    RUN setBrokerURL      IN ptpsession (INPUT "ConnectionFactory").
    RUN setUser           IN ptpsession (INPUT "admin").
    RUN setPassword       IN ptpsession (INPUT "admin").
    
    /* Connect to the broker. */
    RUN beginSession IN ptpsession.
    
    /* Create a text message */
    RUN createTextMessage IN ptpsession (OUTPUT messageH).
    ddate = DATE(cdate).
    RUN setText IN messageH ("This is test message sent.").
    
    /* Publish the message on the "RequestQ" topic */
    RUN sendToQueue IN ptpsession ("example.MyQueue", messageH, ?, ?, ?).
    RUN deleteMessage IN messageH.
    RUN deleteSession IN ptpsession.
    
    Message "Sent".