此内容没有您所选择的语言版本。
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:
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
Copy to Clipboard
Copied!
Toggle word wrap
Toggle overflow
HornetQConnectionFactory
. Here is an example:
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:
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.