Java Code Examples for org.apache.camel.CamelContext#addService()

The following examples show how to use org.apache.camel.CamelContext#addService() . 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: HealthContextCustomizer.java    From camel-k-runtime with Apache License 2.0 7 votes vote down vote up
@Override
public void apply(CamelContext camelContext) {
    try {
        HealthCheckRegistry reg =  HealthCheckRegistry.get(camelContext);
        if (includeRoutes) {
            reg.addRepository(new RoutesHealthCheckRepository());
        }
        if (includeContext) {
            ContextHealthCheck contextHealthCheck = new ContextHealthCheck();
            contextHealthCheck.getConfiguration().setEnabled(true);

            reg.register(contextHealthCheck);
        }

        camelContext.addService(reg);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    // add health route
    addRoute(
        camelContext,
        VertxPlatformHttpRouter.lookup(camelContext)
    );
}
 
Example 2
Source File: PlatformHttpServiceContextCustomizer.java    From camel-k-runtime with Apache License 2.0 6 votes vote down vote up
@Override
public void apply(CamelContext camelContext) {
    try {
        camelContext.addService(new VertxPlatformHttpServer(this) {
            @Override
            protected void doInit() throws Exception {
                initializeServer();
            }
            @Override
            protected void doStart() throws Exception {
                startServer();
            }
        });
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    PlatformHttpComponent component = new PlatformHttpComponent(camelContext);
    component.setEngine(new VertxPlatformHttpEngine());

    camelContext.getRegistry().bind(PlatformHttpConstants.PLATFORM_HTTP_COMPONENT_NAME, component);
}
 
Example 3
Source File: MasterContextCustomizer.java    From camel-k-runtime with Apache License 2.0 5 votes vote down vote up
@Override
public void apply(CamelContext camelContext) {
    try {
        KubernetesClusterService clusterService = new KubernetesClusterService();
        if (ObjectHelper.isNotEmpty(configMapName)) {
            clusterService.setConfigMapName(this.configMapName);
        }
        if (ObjectHelper.isNotEmpty(this.labelKey) && ObjectHelper.isNotEmpty(this.labelValue)) {
            clusterService.setClusterLabels(Collections.singletonMap(this.labelKey, this.labelValue));
        }
        camelContext.addService(clusterService);
    } catch (Exception ex) {
        throw new RuntimeCamelException(ex);
    }
}
 
Example 4
Source File: IntegrationMetadataContextCustomizer.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Override
public void apply(CamelContext camelContext) {
    try {
        // register custom mbean
        camelContext.addService(new CamelContextMetadataMBean());
    } catch (Exception e) {
        ObjectHelper.wrapRuntimeCamelException(e);
    }
    LOGGER.info("Added Syndesis MBean Service");
}
 
Example 5
Source File: SagaIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testPropagationRequired() throws Exception {
    List<String> sagaIds = new LinkedList<>();

    CamelSagaService sagaService = new InMemorySagaService();

    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addService(sagaService);
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:required")
                .saga()
                .process(addSagaIdToList(sagaIds))
                .to("direct:required2");

            from("direct:required2")
                .saga().propagation(SagaPropagation.REQUIRED)
                .process(addSagaIdToList(sagaIds))
                .to("direct:required3");

            from("direct:required3")
                .saga()
                .process(addSagaIdToList(sagaIds));
        }
    });

    camelctx.start();
    try {
        camelctx.createFluentProducerTemplate().to("direct:required").request();

        Assert.assertEquals(3, sagaIds.size());
        assertUniqueNonNullSagaIds(sagaIds, 1);
    } finally {
        camelctx.close();
    }
}
 
Example 6
Source File: SagaIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testPropagationRequiresNew() throws Exception {
    List<String> sagaIds = new LinkedList<>();

    CamelSagaService sagaService = new InMemorySagaService();

    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addService(sagaService);
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:requiresNew")
                .saga().propagation(SagaPropagation.REQUIRES_NEW)
                .process(addSagaIdToList(sagaIds))
                .to("direct:requiresNew2")
                .to("direct:requiresNew2");

            from("direct:requiresNew2")
                .saga().propagation(SagaPropagation.REQUIRES_NEW)
                .process(addSagaIdToList(sagaIds));
        }
    });

    camelctx.start();
    try {
        camelctx.createFluentProducerTemplate().to("direct:requiresNew").request();

        Assert.assertEquals(3, sagaIds.size());
        assertUniqueNonNullSagaIds(sagaIds, 3);
    } finally {
        camelctx.close();
    }
}
 
Example 7
Source File: SagaIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testPropagationNotSupported() throws Exception {
    List<String> sagaIds = new LinkedList<>();

    CamelSagaService sagaService = new InMemorySagaService();

    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addService(sagaService);
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:notSupported")
                .process(addSagaIdToList(sagaIds))
                .to("direct:notSupported2")
                .to("direct:notSupported3");

            from("direct:notSupported2")
                .saga()
                .process(addSagaIdToList(sagaIds))
                .to("direct:notSupported3");

            from("direct:notSupported3")
                .saga().propagation(SagaPropagation.NOT_SUPPORTED)
                .process(addSagaIdToList(sagaIds));
        }
    });

    camelctx.start();
    try {
        camelctx.createFluentProducerTemplate().to("direct:notSupported").request();

        Assert.assertEquals(4, sagaIds.size());
        assertNonNullSagaIds(sagaIds, 1);
    } finally {
        camelctx.close();
    }
}
 
Example 8
Source File: SagaIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testPropagationSupports() throws Exception {
    List<String> sagaIds = new LinkedList<>();

    CamelSagaService sagaService = new InMemorySagaService();

    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addService(sagaService);
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:supports")
                .to("direct:supports2")
                .to("direct:supports3");

            from("direct:supports2")
                .saga()
                .to("direct:supports3");

            from("direct:supports3")
                .saga().propagation(SagaPropagation.SUPPORTS)
                .process(addSagaIdToList(sagaIds));
        }
    });

    camelctx.start();
    try {
        camelctx.createFluentProducerTemplate().to("direct:supports").request();

        Assert.assertEquals(2, sagaIds.size());
        assertUniqueNonNullSagaIds(sagaIds, 1);
    } finally {
        camelctx.close();
    }
}
 
Example 9
Source File: SagaIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testPropagationMandatory() throws Exception {
    List<String> sagaIds = new LinkedList<>();

    CamelSagaService sagaService = new InMemorySagaService();

    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addService(sagaService);
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:mandatory")
                .to("direct:mandatory2");

            from("direct:mandatory2")
                .saga().propagation(SagaPropagation.MANDATORY)
                .process(addSagaIdToList(sagaIds));
        }
    });

    camelctx.start();
    try {
        camelctx.createFluentProducerTemplate().to("direct:mandatory").request();
        Assert.fail("Expected CamelExecutionException to be thrown");
    } catch (CamelExecutionException e) {
        // Expected
    } finally {
        camelctx.close();
    }
}
 
Example 10
Source File: SagaIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testPropagationNever() throws Exception {
    List<String> sagaIds = new LinkedList<>();

    CamelSagaService sagaService = new InMemorySagaService();

    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addService(sagaService);
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:never")
                .saga()
                .to("direct:never2");

            from("direct:never2")
                .saga().propagation(SagaPropagation.NEVER)
                .process(addSagaIdToList(sagaIds));
        }
    });

    camelctx.start();
    try {
        camelctx.createFluentProducerTemplate().to("direct:never").request();
        Assert.fail("Expected CamelExecutionException to be thrown");
    } catch (CamelExecutionException e) {
        // Expected
    } finally {
        camelctx.close();
    }
}
 
Example 11
Source File: LRAIntegrationTest.java    From wildfly-camel with Apache License 2.0 4 votes vote down vote up
private CamelContext createCamelContext() throws Exception {
    CamelContext camelctx = new DefaultCamelContext();
    camelctx.addService(createLRASagaService());

    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            restConfiguration()
                .component("undertow")
                .contextPath("/lra");
        }
    });

    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            orderManagerService = new OrderManagerService();
            creditService = new CreditService(100);

            from("direct:saga")
                .saga().propagation(SagaPropagation.REQUIRES_NEW)
                .log("Creating a new order")
                .to("direct:newOrder")
                .log("Taking the credit")
                .to("direct:reserveCredit")
                .log("Finalizing")
                .to("direct:finalize")
                .log("Done!");

            // Order service
            from("direct:newOrder")
                .saga()
                .propagation(SagaPropagation.MANDATORY)
                .compensation("direct:cancelOrder")
                .transform().header(Exchange.SAGA_LONG_RUNNING_ACTION)
                .bean(orderManagerService, "newOrder")
                .log("Order ${body} created");

            from("direct:cancelOrder")
                .transform().header(Exchange.SAGA_LONG_RUNNING_ACTION)
                .bean(orderManagerService, "cancelOrder")
                .log("Order ${body} cancelled");

            // Credit service
            from("direct:reserveCredit")
                .saga()
                .propagation(SagaPropagation.MANDATORY)
                .compensation("direct:refundCredit")
                .transform().header(Exchange.SAGA_LONG_RUNNING_ACTION)
                .bean(creditService, "reserveCredit")
                .log("Credit ${header.amount} reserved in action ${body}");

            from("direct:refundCredit")
                .transform().header(Exchange.SAGA_LONG_RUNNING_ACTION)
                .bean(creditService, "refundCredit")
                .log("Credit for action ${body} refunded");

            // Final actions
            from("direct:finalize")
                .saga().propagation(SagaPropagation.NOT_SUPPORTED)
                .choice()
                .when(header("fail").isEqualTo(true))
                .process(x -> {
                    throw new RuntimeException("fail");
                })
                .end();
        }
    });

    return camelctx;
}