173.6.3. 在集群内保留单例路由
以下代码片段演示了如何将单例使用者路由保留在 Camel 上下文的群集中。一旦 master 节点出现问题,其中一个从节点就被选为新的 master 并已启动。在这个特定示例中,我们希望使 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");