24.3. Configure JGroups (Library Mode)
Red Hat JBoss Data Grid must have an appropriate JGroups configuration in order to operate in clustered mode.
To configure JGroups programmatically use the following:
GlobalConfiguration gc = new GlobalConfigurationBuilder() .transport() .defaultTransport() .addProperty("configurationFile","jgroups.xml") .build();
To configure JGroups using XML use the following:
<infinispan> <global> <transport> <properties> <property name="configurationFile" value="jgroups.xml" /> </properties> </transport> </global> ... </infinispan>
In either programmatic or XML configuration methods, JBoss Data Grid searches for
jgroups.xml
in the classpath before searching for an absolute path name if it is not found in the classpath.
24.3.1. JGroups Transport Protocols
A transport protocol is the protocol at the bottom of a protocol stack. Transport Protocols are responsible for sending and receiving messages from the network.
Red Hat JBoss Data Grid ships with both UDP and TCP transport protocols.
24.3.1.1. The UDP Transport Protocol
UDP is a transport protocol that uses:
- IP multicasting to send messages to all members of a cluster.
- UDP datagrams for unicast messages, which are sent to a single member.
When the UDP transport is started, it opens a unicast socket and a multicast socket. The unicast socket is used to send and receive unicast messages, the multicast socket sends and receives multicast sockets. The physical address of the channel with be the same as the address and port number of the unicast socket.
24.3.1.2. The TCP Transport Protocol
TCP/IP is a replacement transport for UDP in situations where IP multicast cannot be used, such as operations over a WAN where routers may discard IP multicast packets.
TCP is a transport protocol used to send unicast and multicast messages.
- When sending multicast messages, TCP sends multiple unicast messages.
- When using TCP, each message to all cluster members is sent as multiple unicast messages, or one to each member.
As IP multicasting cannot be used to discover initial members, another mechanism must be used to find initial membership.
Red Hat JBoss Data Grid's Hot Rod is a custom TCP client/server protocol.
24.3.1.3. Using the TCPPing Protocol
Some networks only allow TCP to be used. The pre-configured
jgroups-tcp.xml
includes the MPING
protocol, which uses UDP
multicast for discovery. When UDP
multicast is not available, the MPING
protocol, has to be replaced by a different mechanism. The recommended alternative is the TCPPING
protocol. The TCPPING
configuration contains a static list of IP addresses which are contacted for node discovery.
The following is an example of how to configure the JGroups subsystem to use
TCPPING
.
<TCP bind_port="7800" /> <TCPPING timeout="3000" initial_hosts="${jgroups.tcpping.initial_hosts:HostA[7800],HostB[7801]}" port_range="1" num_initial_members="3"/>