You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 13 Next »

JGroups Component

Available since Camel 2.10.0

 

JGroups is a toolkit for reliable multicast communication. The jgroups: component provides exchange of messages between Camel infrastructure and JGroups clusters.

Maven users will need to add the following dependency to their pom.xml for this component.

<dependency>
    <groupId>org.apache-extras.camel-extra</groupId>
    <artifactId>camel-jgroups</artifactId>
    <!-- use the same version as your Camel core version -->
    <version>x.y.z</version>
</dependency>

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.

<dependency>
    <groupId>org.apache.camel</groupId>
    <artifactId>camel-jgroups</artifactId>
    <!-- use the same version as your Camel core version -->
    <version>x.y.z</version>
</dependency>

URI format

jgroups:clusterName[?options]

Where clusterName represents the name of the JGroups cluster the component should connect to.

Options

Name

Default Value

Description

channelProperties

null

Camel 2.10.0: Specifies configuration properties of the JChannel used by the endpoint.

enableViewMessagesfalseCamel 2.13.0:  Consumer only. If set to true, the consumer endpoint will receive org.jgroups.View messages as well (not only org.jgroups.Message instances). By default only regular messages are consumed by the endpoint.

Headers

HeaderConstantSince versionDescription
JGROUPS_ORIGINAL_MESSAGEJGroupsEndpoint.HEADER_JGROUPS_ORIGINAL_MESSAGE2.13.0The original org.jgroups.Message instance from which the body of the consumed message has been extracted.
JGROUPS_SRCJGroupsEndpoint.HEADER_JGROUPS_SRC2.10.0The org.jgroups.Address instance extracted by org.jgroups.Message.getSrc() method of the consumed message.
JGROUPS_DESTJGroupsEndpoint.HEADER_JGROUPS_DEST2.10.0The org.jgroups.Address instance extracted by org.jgroups.Message.getDest() method of the consumed message.
JGROUPS_CHANNEL_ADDRESSJGroupsEndpoint.HEADER_JGROUPS_CHANNEL_ADDRESS2.13.0Address (org.jgroups.Address) of the channel associated with the endpoint.

 

Usage

Using 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.

// Capture messages from cluster named
// 'clusterName' and send them to Camel route.
from("jgroups:clusterName").to("seda:queue");

Using jgroups component on the producer side of the route will forward body of the Camel exchanges to the JChannel instance managed by the endpoint.

// Send message to the cluster named 'clusterName'
from("direct:start").to("jgroups:clusterName");

Predefined filters

JGroups component comes with predefined filters factory class named JGroupsFilters.

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.

Examples

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.

mockEndpoint.setExpectedMessageCount(1);
mockEndpoint.message(0).body().isInstanceOf(org.jgroups.View.class);
from("jgroups:clusterName?enableViewMessages=true").to(mockEndpoint);
mockEndpoint.assertIsSatisfied();
  • No labels