此内容没有您所选择的语言版本。

36.5. Specifying Members of a Cluster Explicitly


Sometimes UDP is not enabled on a network so it is not possible to use UDP server discovery for clients to discover the list of servers in the cluster, or for servers to discover what other servers are in the cluster.
In this case, the list of servers in the cluster can be specified explicitly on each node and on the client side. This is done as follows:

36.5.1. Specify List of Servers on the Client Side

This differs depending on whether you are using JMS or the Core API.

36.5.1.1. Specifying List of Servers using JMS

If using JMS and 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 JBOSS_DIST/jboss-as/server/<PROFILE>/deploy/hornetq/hornetq-jms.xml. Let us take a look at an example:
<connection-factory name="ConnectionFactory">
   <connectors>
      <connector-ref connector-name="my-connector1" 
       backup-connector-name="my-backup-connector1"/>
      <connector-ref connector-name="my-connector2" 
       backup-connector-name="my-backup-connector2"/>
      <connector-ref connector-name="my-connector3" 
       backup-connector-name="my-backup-connector3"/>
   </connectors>
   <entries>
      <entry name="/ConnectionFactory"/>
   </entries>
</connection-factory>
Copy to Clipboard Toggle word wrap
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 <JBOSS_HOME>/jboss-as/server/<PROFILE>/deploy/hornetq/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 refer to Chapter 14, 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 are using JMS but you are not using JNDI then you can also specify the list of [connector, backup connector] pairs directly when instantiating the HornetQConnectionFactory. Here is an example:
List<Pair<TransportConfiguration, TransportConfiguration>> serverList = 
        new ArrayList<Pair<TransportConfiguration, TransportConfiguration>>();

serverList.add(new Pair<TransportConfiguration, 
        TransportConfiguration>(liveTC0, backupTC0));
serverList.add(new Pair<TransportConfiguration, 
        TransportConfiguration>(liveTC1, backupTC1));
serverList.add(new Pair<TransportConfiguration, 
        TransportConfiguration>(liveTC2, backupTC2));

ConnectionFactory jmsConnectionFactory = HornetQJMSClient.createConnectionFactory(serverList);

Connection jmsConnection1 = jmsConnectionFactory.createConnection();

Connection jmsConnection2 = jmsConnectionFactory.createConnection();
Copy to Clipboard Toggle word wrap
The above snippet creates a list of pairs of TransportConfiguration objects. Each TransportConfiguration object contains knowledge of how to make a connection to a specific server.
Create a HornetQConnectionFactory instance, 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.

36.5.1.2. Specifying List of Servers using the Core API

Specify the list of servers directly when creating the ClientSessionFactory instance as in the following example:
List<Pair<TransportConfiguration, TransportConfiguration>> serverList = 
        new ArrayList<Pair<TransportConfiguration, TransportConfiguration>>();

serverList.add(new Pair<TransportConfiguration, 
        TransportConfiguration>(liveTC0, backupTC0));
serverList.add(new Pair<TransportConfiguration, 
        TransportConfiguration>(liveTC1, backupTC1));
serverList.add(new Pair<TransportConfiguration, 
        TransportConfiguration>(liveTC2, backupTC2));

ClientSessionFactory factory = HornetQClient.createClientSessionFactory(serverList);

ClientSession session1 = factory.createClientSession(...);

ClientSession session2 = factory.createClientSession(...);
Copy to Clipboard Toggle word wrap
The above snippet creates a list of pairs of TransportConfiguration objects. Each TransportConfiguration object contains knowledge of how to make a connection to a specific server. For more information on this, refer to Chapter 14, Configuring the Transport.
A ClientSessionFactoryImpl instance is then created passing the list of servers in the constructor. Any sessions subsequently created by this factory will create sessions according to the client connection load balancing policy applied to that list of servers.
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat