173.6.3. 클러스터 내에 Singleton 경로 유지
아래 코드 조각은 Camel Context의 클러스터에 Singleton 소비자 경로를 유지하는 방법을 보여줍니다. 마스터 노드가 종료되는 즉시 새 마스터로 슬레이브 중 하나가 선택됩니다. 이 특정 예제에서는 Singleton jetty 인스턴스가 주소의 http://localhost:8080/orders` 에서 요청을 수신 대기하도록 유지합니다.
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");