Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: [JGroups] Added conditional delaying information

...

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

JGroups component comes with predefined expressions factory class named JGroupsExpressions.

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.

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

Receive cluster view change notifications

...