Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

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

Consumer: The org.jgroups.Address instance extracted by org.jgroups.Message.getSrc() method of the consumed message.

Producer: The custom source org.jgroups.Address of the message to be sent.

JGROUPS_DESTJGroupsEndpoint.HEADER_JGROUPS_DEST2.10.0

Consumer: The org.jgroups.Address instance extracted by org.jgroups.Message.getDest() method of the consumed message.

Producer: The custom destination org.jgroups.Address of the message to be sent.

JGROUPS_CHANNEL_ADDRESSJGroupsEndpoint.HEADER_JGROUPS_CHANNEL_ADDRESS2.13.0Address (org.jgroups.Address) of the channel associated with the endpoint.

...

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

Predefined filters

Starting from version 2.13.0 of Camel, JGroups component comes with predefined filters factory class named JGroupsFilters.

...

Code Block
java
java
import static org.apache.camel.component.jgroups.JGroupsFilters.dropNonCoordinatorViews;
...
from("jgroups:clusterName?enableViewMessages=true").
  filter(dropNonCoordinatorViews()).
  to("seda:masterNodeEventsQueue");

Predefined expressions

Starting from version 2.13.0 of Camel, JGroups component comes with predefined expressions factory class named JGroupsExpressions.

...

Code Block
java
java
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.apache.camel.component.jgroups.JGroupsExpressions.delayIfContextNotStarted;
import static org.apache.camel.component.jgroups.JGroupsFilters.dropNonCoordinatorViews;
...
from("jgroups:clusterName?enableViewMessages=true").
  filter(dropNonCoordinatorViews()).
  threads().delay(delayIfContextNotStarted(SECONDS.toMillis(5))). // run in separated and delayed thread. Delay only if the context hasn't been started already. 
  to("controlbus:route?routeId=masterRoute&action=start&async=true");

from("timer://master?repeatCount=1").routeId("masterRoute").autoStartup(false).to(masterMockUri); 

Examples

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.

Code Block
java
java
from("direct:start").to("jgroups:myCluster");
...
producerTemplate.sendBody("direct:start", "msg")

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.

Code Block
java
java
mockEndpoint.setExpectedMessageCount(1);
mockEndpoint.message(0).body().isEqualTo("msg");
...
from("jgroups:myCluster").to("mock:messagesFromTheCluster");
...
mockEndpoint.assertIsSatisfied();

Receive cluster view change notifications

...

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

...