Camel 버전 2.1 부터,ECDHE 구성 요소에는ECDHE Expressions라는 사전 정의된 표현식이 포함되어 있습니다.
Camel 컨텍스트가 아직 시작되지 않은 경우에만 경로에 영향을 주는 지연기를 생성하려면ECDHE Expressions.delayIfContextNotStarted(long delay) 팩토리 방법을 사용합니다. 이 팩토리 메서드에서 생성한 표현식은 Camel 컨텍스트가 시작된 상태와 다른 경우에만 지정된 지연 값을 반환합니다. 이 표현식은 클러스터 내에서 singleton(마스터) 경로를 유지하기 위해ECDHE 구성 요소를 사용하려는 경우에 특히 유용합니다. Camel 컨텍스트가 아직 시작되지 않은 경우 Control Busstart 명령이 singleton 경로를 초기화하지 않습니다. 따라서 마스터 경로 시작 시간을 지연하여 Camel 컨텍스트 시작 후 초기화되었는지 확인해야 합니다. 이러한 시나리오는 클러스터 초기화 중에만 발생할 수 있으므로 슬레이브 노드의 시작을 새 마스터가 되는 것을 지연시키지 않습니다. 따라서 조건부 지연 표현이 필요합니다.
아래 스니펫은 cluster에서 마스터 노드의 초기 시작을 지연하기 위해ECDHE 구성 요소와 조건부 지연을 사용하는 방법을 보여줍니다.
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);
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);
Copy to ClipboardCopied!Toggle word wrapToggle overflow