Available since Camel 2.10.0
Maven users will need to add the following dependency to their
pom.xml for this component.
Starting from the Camel 2.13.0, JGroups component has been moved from Camel Extra under the umbrella of the Apache Camel. If you are using Camel 2.13.0 or higher, please use the following POM entry instead.
Where clusterName represents the name of the JGroups cluster the component should connect to.
Camel 2.10.0: Specifies configuration properties of the JChannel used by the endpoint.
|Camel 2.13.0: Consumer only. If set to |
|2.13.0||The original |
Producer: The custom source
Producer: The custom destination
jgroups component on the consumer side of the route will capture messages received by the
JChannel associated with the endpoint and forward them to the Camel route. JGroups consumer processes incoming messages asynchronously.
jgroups component on the producer side of the route will forward body of the Camel exchanges to the
JChannel instance managed by the endpoint.
Starting from version 2.13.0 of Camel, JGroups component comes with predefined filters factory class named
If you would like to consume only view changes notifications sent to coordinator of the cluster (and ignore these sent to the "slave" nodes), use the
JGroupsFilters.dropNonCoordinatorViews() filter. This filter is particularly useful when you want a single Camel node to become the master in the cluster, because messages passing this filter notifies you when given node has become a coordinator of the cluster. The snippet below demonstrates how to collect only messages received by the master node.
Starting from version 2.13.0 of Camel, JGroups component comes with predefined expressions factory class named
If you would like to create delayer that would affect the route only if the Camel context has not been started yet, use the
JGroupsExpressions.delayIfContextNotStarted(long delay) factory method. The expression created by this factory method will return given delay value only if the Camel context is in the state different than
started. This expression is particularly useful if you would like to use JGroups component for keeping singleton (master) route within the cluster. Control Bus
start command won't initialize the singleton route if the Camel Context hasn't been yet started. So you need to delay a startup of the master route, to be sure that it has been initialized after the Camel Context startup. Because such scenario can happen only during the initialization of the cluster, we don't want to delay startup of the slave node becoming the new master - that's why we need a conditional delay expression.
The snippet below demonstrates how to use conditional delaying with the JGroups component to delay the initial startup of master node in the cluster.
Sending (receiving) messages to (from) the JGroups cluster
In order to send message to the JGroups cluster use producer endpoint, just as demonstrated on the snippet below.
To receive the message from the snippet above (on the same or the other physical machine) listen on the messages coming from the given cluster, just as demonstrated on the code fragment below.
Receive cluster view change notifications
The snippet below demonstrates how to create the consumer endpoint listening to the notifications regarding cluster membership changes. By default only regular messages are consumed by the endpoint.
Keeping singleton route within the cluster
The snippet below demonstrates how to keep the singleton consumer route in the cluster of Camel Contexts. As soon as the master node dies, one of the slaves will be elected as a new master and started. In this particular example we want to keep singleton jetty instance listening for the requests on address