Specify List of Servers using JMS
38.5.1.1. Specifying List of Servers using JMS If you're using JMS, and you're using the JMS Service to load your JMS connection factory instances directly into JNDI on the server, then you can specify the list of servers in the server side configuration file hornetq-jms.xml. Let's take a look at an example: The connection-factory element can contain zero or more connector-ref elements, each one of which specifies a connector-name attribute and an optional backup-connector-name attribute. The connector-name attribute references a connector defined in hornetq-configuration.xml which will be used as a live connector. The backup-connector-name is optional, and if specified it also references a connector defined in hornetq-configuration.xml. For more information on connectors please see Chapter 16, Configuring the Transport. The connection factory thus maintains a list of [connector, backup connector] pairs, these pairs are then used by the client connection load balancing policy on the client side when creating connections to the cluster. If you're using JMS but you're not using JNDI then you can also specify the list of [connector, backup connector] pairs directly when instantiating the HornetQConnectionFactory, here's an example: List> serverList = new ArrayList>(); serverList.add(new Pair(liveTC0, backupTC0)); serverList.add(new Pair(liveTC1, backupTC1)); serverList.add(new Pair(liveTC2, backupTC2)); ConnectionFactory jmsConnectionFactory = HornetQJMSClient.createConnectionFactory(serverList); Connection jmsConnection1 = jmsConnectionFactory.createConnection(); Connection jmsConnection2 = jmsConnectionFactory.createConnection(); In the above snippet we create a list of pairs of TransportConfiguration objects. Each TransportConfiguration object contains knowledge of how to make a connection to a specific server. A HornetQConnectionFactory instance is then created passing the list of servers in the constructor. Any connections subsequently created by this factory will create connections according to the client connection load balancing policy applied to that list of servers.