本文整理汇总了Java中org.apache.camel.model.ModelCamelContext.addRoutes方法的典型用法代码示例。如果您正苦于以下问题:Java ModelCamelContext.addRoutes方法的具体用法?Java ModelCamelContext.addRoutes怎么用?Java ModelCamelContext.addRoutes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.camel.model.ModelCamelContext
的用法示例。
在下文中一共展示了ModelCamelContext.addRoutes方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createContextWithGivenRoute
import org.apache.camel.model.ModelCamelContext; //导入方法依赖的package包/类
protected void createContextWithGivenRoute(RouteBuilder route, int timeWork) throws Exception, InterruptedException {
SimpleRegistry registry = new SimpleRegistry();
ModelCamelContext context = new DefaultCamelContext(registry);
Tracer tracer = new Tracer();
tracer.setLogName("MyTracerLog");
tracer.getDefaultTraceFormatter().setShowProperties(false);
tracer.getDefaultTraceFormatter().setShowHeaders(false);
tracer.getDefaultTraceFormatter().setShowBody(true);
context.addInterceptStrategy(tracer);
context.addRoutes(route);
context.addComponent("activeMq", activeMq);
this.camelContext = context;
this.ct = context.createConsumerTemplate();
this.pt = context.createProducerTemplate();
context.start();
context.setTracing(false);
Thread.sleep(timeWork);
context.stop();
}
示例2: main
import org.apache.camel.model.ModelCamelContext; //导入方法依赖的package包/类
public static void main(String... args) throws Exception {
// 这是camel上下文对象,整个路由的驱动全靠它了。
ModelCamelContext camelContext = new DefaultCamelContext();
// 启动route
camelContext.start();
// 将我们编排的一个完整消息路由过程,加入到上下文中
camelContext.addRoutes(new ApacheCamelExample());
/*
* ==========================
* 为什么我们先启动一个Camel服务
* 再使用addRoutes添加编排好的路由呢?
* 这是为了告诉各位读者,Apache Camel支持 动态加载/卸载编排 的路由
* 这很重要,因为后续设计的Broker需要依赖这种能力
* ==========================
*/
// 通用没有具体业务意义的代码,只是为了保证主线程不退出
synchronized (ApacheCamelExample.class) {
ApacheCamelExample.class.wait();
}
}
示例3: main
import org.apache.camel.model.ModelCamelContext; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
// 这是camel上下文对象,整个路由的驱动全靠它了
ModelCamelContext camelContext = new DefaultCamelContext();
// 启动route
camelContext.start();
// 首先将两个完整有效的路由注册到Camel服务中
camelContext.addRoutes(new DirectRouterExample().new DirectRouteA());
camelContext.addRoutes(new DirectRouterExample().new DirectRouteB());
// 通用没有具体业务意义的代码,只是为了保证主线程不退出
synchronized (DirectRouterExample.class) {
DirectRouterExample.class.wait();
}
}
示例4: setUp
import org.apache.camel.model.ModelCamelContext; //导入方法依赖的package包/类
@Override
protected void setUp() throws Exception {
// make SEDA testing faster
System.setProperty("CamelSedaPollTimeout", "10");
if (!useJmx()) {
disableJMX();
} else {
enableJMX();
}
CamelContext c2 = createCamelContext();
if (c2 instanceof ModelCamelContext) {
context = (ModelCamelContext)c2;
} else {
throw new Exception("Context must be a ModelCamelContext");
}
assertValidContext(context);
// reduce default shutdown timeout to avoid waiting for 300 seconds
context.getShutdownStrategy().setTimeout(10);
template = context.createProducerTemplate();
template.start();
consumer = context.createConsumerTemplate();
consumer.start();
// create a default notifier when 1 exchange is done which is the most common case
oneExchangeDone = event().whenDone(1).create();
if (isUseRouteBuilder()) {
RouteBuilder[] builders = createRouteBuilders();
for (RouteBuilder builder : builders) {
log.debug("Using created route builder: " + builder);
context.addRoutes(builder);
}
startCamelContext();
} else {
log.debug("isUseRouteBuilder() is false");
}
}
示例5: doSetUp
import org.apache.camel.model.ModelCamelContext; //导入方法依赖的package包/类
private void doSetUp() throws Exception {
log.debug("setUp test");
if (!useJmx()) {
disableJMX();
} else {
enableJMX();
}
CamelContext c2 = createCamelContext();
if (c2 instanceof ModelCamelContext) {
context = (ModelCamelContext)c2;
} else {
throw new Exception("Context must be a ModelCamelContext");
}
threadCamelContext.set(context);
assertNotNull(context, "No context found!");
// reduce default shutdown timeout to avoid waiting for 300 seconds
context.getShutdownStrategy().setTimeout(getShutdownTimeout());
// set debugger if enabled
if (isUseDebugger()) {
context.setDebugger(new DefaultDebugger());
context.getDebugger().addBreakpoint(breakpoint);
// note: when stopping CamelContext it will automatic remove the breakpoint
}
template = context.createProducerTemplate();
template.start();
consumer = context.createConsumerTemplate();
consumer.start();
threadTemplate.set(template);
threadConsumer.set(consumer);
// enable auto mocking if enabled
String pattern = isMockEndpoints();
if (pattern != null) {
context.addRegisterEndpointCallback(new InterceptSendToMockEndpointStrategy(pattern));
}
pattern = isMockEndpointsAndSkip();
if (pattern != null) {
context.addRegisterEndpointCallback(new InterceptSendToMockEndpointStrategy(pattern, true));
}
// configure properties component (mandatory for testing)
context.getComponent("properties", PropertiesComponent.class);
postProcessTest();
if (isUseRouteBuilder()) {
RoutesBuilder[] builders = createRouteBuilders();
for (RoutesBuilder builder : builders) {
log.debug("Using created route builder: " + builder);
context.addRoutes(builder);
}
boolean skip = "true".equalsIgnoreCase(System.getProperty("skipStartingCamelContext"));
if (skip) {
log.info("Skipping starting CamelContext as system property skipStartingCamelContext is set to be true.");
} else if (isUseAdviceWith()) {
log.info("Skipping starting CamelContext as isUseAdviceWith is set to true.");
} else {
startCamelContext();
}
} else {
log.debug("Using route builder from the created context: " + context);
}
log.debug("Routing Rules are: " + context.getRoutes());
assertValidContext(context);
INIT.set(true);
}