The HATopicPublisher and HADurableSubscriber applications

The HATopicPublisher and HADurableSubscriber applications demonstrate how to enable JMS client applications to use Eclipse Amlen high availability features.

These applications are in the com.ibm.ima.samples.jms package and are designed to work with each other. The HATopicPublisher publishes messages to a durable topic and the HADurableSubscriber reads messages from that topic. These samples show how to use built-in high availability features in the Eclipse Amlen JMS client, and how client applications can function with resilience when the primary server goes down and the standby server becomes the primary server in a high availability configuration.

A high availability configuration provides the following features:
  • The ability to use the client Server ConnectionFactory property to configure the list of host names (or IP addresses) for the configured high availability servers.
  • The ability to use the client isClosed property to determine whether the connection to the server was lost when a failure is reported.
When the ConnectionFactory Server property contains a list of servers, the Eclipse Amlen JMS client attempts to connect to each server in the list until a successful connection is established. If a client application is connected to a server that goes down, the Eclipse Amlen JMS client sets the isClosed property in the Connection object to true. Client applications always check the isClosed property when failures occur. When a client application finds that isClosed is true, a new connection is created so that processing can continue.
Note: During failover or synchronization the primary server might not be responsive for some time, depending on the current server state.

You can run the HATopicPublisher application by using the following command. The command consists of five required positional arguments and three more positional arguments that are optional.

java com.ibm.ima.samples.jms.HATopicPublisher serverlist serverport topicname count messagetext [msgspersec] [initdurablesub] [debug]

Where the positional arguments are:

serverlist
A string that represents a list of Eclipse Amlen server host names or IP addresses. This list can be comma or space delimited.
serverport
An integer value that represents the port number for connections to the Eclipse Amlen server.
topicname
A string that represents the name of the topic destination for published messages.
count
An integer value that represents the number of messages to publish.
messagetext
A string that represents the content of the published messages.
msgspersec
Optional.
An integer value that represents the number of messages to send per second. The default value is 5000.
initdurablesub
Optional.
A Boolean value that indicates whether a durable subscription is initialized for the specified topic. The default value is true.
As initdurablesub is a positional argument, if you change the default value then you must specify msgspersec in the command.
debug
Optional.
A Boolean value that indicates whether to provide debug output from the application. The default value is false.
As debug is a positional argument, if you change the default value then you must specify msgspersec and initdurablesub in the command.

You can run the HADurableSubscriber application by using the following command. The command consists of four required positional arguments and a fifth positional argument that is optional.

java com.ibm.ima.samples.jms.HADurableSubscriber serverlist serverport topicname count [receivetimeout]

Where the positional arguments are:

serverlist
A string that represents a list of Eclipse Amlen server host names or IP addresses. This list can be comma or space delimited.
serverport
An integer value that represents the port number for connections to the Eclipse Amlen server.
topicname
A string that represents the durable subscription topic name.
count
An integer value that represents the number of messages to receive.
receivetimeout
Optional.
The number of seconds to wait for the first message to be received. The default value is 10 seconds.

Examples

The following commands show examples of the arguments that you can use to run the HATopicPublisher application.

This example uses the default values of the optional arguments.

java com.ibm.ima.samples.jms.HATopicPublisher "server1.example.com, server2.example.com" 16102  durableTopic 2000 "Test message"

This example sets debug to true rather than using the default value of false. This setting means that debug output is provided. As debug is a positional argument, the values of msgspersec and initdurablesub must be specified even when the default values are used.

java com.ibm.ima.samples.jms.HATopicPublisher "server1.example.com, server2.example.com" 16102  durableTopic 2000 "Test message" 5000 true true 

The following commands show examples of the arguments that you can use to run the HADurableSubscriber application.

This example uses the default receivetimeout value of 10 seconds.

java com.ibm.ima.samples.jms.HADurableSubscriber "server1.example.com, server2.example.com" 16102  durableTopic 2000

This example sets the receivetimeout value to 60 seconds.

java com.ibm.ima.samples.jms.HADurableSubscriber "server1.example.com, server2.example.com" 16102  durableTopic 2000 60