Java Code Examples for org.apache.camel.model.ModelCamelContext#start()

The following examples show how to use org.apache.camel.model.ModelCamelContext#start() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ApacheCamelExample.java    From yuzhouwan with Apache License 2.0 6 votes vote down vote up
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();
        }
    }
 
Example 2
Source File: JAXBInitalizationTest.java    From wildfly-camel with Apache License 2.0 6 votes vote down vote up
@Test
public void testJaxbDumpModelAsXML() throws Exception {

	ModelCamelContext camelctx = new DefaultCamelContext();
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start")
            .routeId("route-1")
            .to("log:test");
        }
    });

    camelctx.start();

    try {
        ModelToXMLDumper dumper = camelctx.adapt(ExtendedCamelContext.class).getModelToXMLDumper();
        String xml = dumper.dumpModelAsXml(camelctx, camelctx.getRouteDefinition("route-1"));
        Assert.assertTrue(xml.contains("log:test"));
    } finally {
        camelctx.close();
    }
}
 
Example 3
Source File: MqttOnCamelMqttToLinkIntegrationTest.java    From Ardulink-2 with Apache License 2.0 5 votes vote down vote up
private CamelContext camelContext(Topics topics) throws Exception {
	ModelCamelContext context = new DefaultCamelContext();
	MqttConnectionProperties mqtt = new MqttConnectionProperties().name("foo").brokerHost(brokerHost())
			.brokerPort(brokerPort());
	new MqttCamelRouteBuilder(context, topics).fromSomethingToMqtt(MOCK, mqtt).andReverse();
	adviceAll(context, d -> d.getInput().getEndpointUri().equals(MOCK), a -> a.replaceFromWith("direct:noop"));
	// CamelContext#start is async so it does not guarantee that routes are ready,
	// so we call #startRouteDefinitions
	context.startRouteDefinitions();
	context.start();
	return context;
}
 
Example 4
Source File: DirectRouterExample.java    From yuzhouwan with Apache License 2.0 5 votes vote down vote up
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();
        }
    }