Glassfish Instance with MQ HA Broker Cluster as Remote JMS Provider

Setup a MQ HA Broker Cluster with 3 brokers (b1,b2,b3)

  1. Copy Derby Client jdbc driver (derbyclient.jar) to MQ External Directory
  2. Common MQ Broker Configuration Needed for All the Brokers
    imq.persist.jdbc.derby.createdburl=jdbc:derby://derby-host:1527/mqdb;create=true
    imq.instanceconfig.version=300
    imq.persist.jdbc.dbVendor=derby
    imq.persist.jdbc.derby.driver=org.apache.derby.jdbc.ClientDriver
    imq.cluster.clusterid=cluster1
    imq.persist.jdbc.derby.closedburl==jdbc:derby://derby-host:1527/mqdb;shutdown=true
    imq.persist.store=jdbc
    imq.persist.jdbc.derby.opendburl=jdbc:derby://derby-host:1527/mqdb
    imq.cluster.ha=true
  3. Startup the Derby database (startNetworkServer -h 0.0.0.0)
  4. Start the MQ Brokers
    imqbrokerd -tty -name b1 -Dimq.brokerid=b1 -port 7777 -cluster :7778,:7779
    imqbrokerd -tty -name b2 -Dimq.brokerid=b2 -port 7778 -cluster :7777,:7779
    imqbrokerd -tty -name b3 -Dimq.brokerid=b3 -port 7779 -cluster :7777,:7778
    Now the Brokers should start up in High Availability Mode with JavaDB as the Database

Set MQ HA Cluster as the Remote JMS Provider for Glassfish

  1. Start up Glassfish Domain Admin Server
    asadmin start-domain
  2. Create a Glassfish instanceas
    asadmin create-local-instance instance1
  3. Set the MQ HA Cluster as the Remote JMS Provider
    asadmin set instance1.jms-service.type=REMOTE
    asadmin set instance1.jms-service.jms-host.default_JMS_host.port=7777
  4. Start the Glassfish Instance
    asadmin start-local-instance instance1

Create the JMS Resources

asadmin create-jms-resource --target instance1 --restype javax.jms.QueueConnectionFactory --property ReconnectEnabled=true:AddressList=\\:7777,\\:7778,\\:7779 outboundQueueFactory
asadmin create-jms-resource --target instance1 --restype javax.jms.Queue --property imqDestinationName=inboundQueue inboundQueue
asadmin create-jms-resource --target instance1 --restype javax.jms.Queue --property imqDestinationName=outboundQueue outboundQueue

Deploy the MDB

asadmin deploy --target instance1 simplemdb.ear

Start the Sender and then the Receiver

java -DimqBrokerHostPort=7777 Sender
java -DimqBrokerHostPort=7777 Receiver
Sender will send 10 messages to destination inboundQueue
MDB's consume from this destination and send a reply message to outboundQueue
Receiver will receive all the 10 messages from the destination outboundQueue

Cleanup

asadmin undeploy --target instance1 simplemdb
asadmin delete-jms-resource --target instance1 inboundQueue
asadmin delete-jms-resource --target instance1 outboundQueue
asadmin delete-jms-resource --target instance1 outboundQueueFactory
asadmin stop-local-instance instance1
asadmin delete-local-instance instance1
asadmin stop-domain

imqcmd shutdown bkr -b :7777
imqcmd shutdown bkr -b :7777
imqcmd shutdown bkr -b :7777