Sun GlassFish Message Queue 4.4 Developer's Guide for Java Clients

Single-Broker Auto-Reconnect

Configure your connection-factory object as follows:

Example 3–3 Example of Command to Configure a Single Broker

imqobjmgr add -t cf -l "cn=myConnectionFactory" \
    -o "imqAddressList=mq://jpgserv/jms" \
    -o "imqReconnect=true" \
    -o "imqReconnectAttempts=10"
    -j "java.naming.factory.initial = 
    -j "java.naming.provider.url= file:///home/foo/imq_admin_objects"  

This command creates a connection-factory object with a single address in the broker address list. If connection fails, the client runtime will try to reconnect with the broker 10 times. If an attempt to reconnect fails, the client runtime will sleep for three seconds (the default value for the imqReconnectInterval attribute) before trying again. After 10 unsuccessful attempts, the application will receive a JMSException .

You can ensure that the broker starts automatically at system start-up time. See Starting Brokers Automatically in Sun GlassFish Message Queue 4.4 Administration Guide for information on how to configure automatic broker start-up. For example, on the Solaris platform, you can use /etc/rc.d scripts.