165.6.3. クラスター内でのシングルトンルートの維持
以下のスニペットは、Camel コンテキストのクラスターでシングルトンコンシューマールートを保持する方法を示しています。マスターノードが停止したら、スレーブの 1 つが新しいマスターとして選択され、起動します。この例では、アドレスの http://localhost:8080/orders` のリクエストをリッスンするシングルトン jetty インスタンスを維持します。
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("jetty:http://localhost:8080/orders").routeId("masterRoute").autoStartup(false).to("jms:orders");