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

The following examples show how to use org.apache.camel.CamelContext#setMessageHistoryFactory() . 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: CamelMicroProfileMetricsRecorder.java    From camel-quarkus with Apache License 2.0 5 votes vote down vote up
@Override
public void customize(CamelContext camelContext) {
    if (!config.enableMessageHistory) {
        return;
    }

    if (!camelContext.isMessageHistory()) {
        LOGGER.warn(
                "MessageHistory is not use and will be enabled as required by MicroProfile Metrics for MessageHistory");

        camelContext.setMessageHistory(true);
    }

    camelContext.setMessageHistoryFactory(new MicroProfileMetricsMessageHistoryFactory());
}
 
Example 2
Source File: MicrometerCounterIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
private CamelContext createCamelContext() throws Exception {
    CamelContext camelctx = new DefaultCamelContext(new JndiBeanRepository());
    camelctx.addRoutePolicyFactory(new MicrometerRoutePolicyFactory());
    camelctx.setMessageHistoryFactory(new MicrometerMessageHistoryFactory());
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:in-1")
                .to("micrometer:counter:A?increment=5")
                .to("mock:out");

            from("direct:in-2")
                .to("micrometer:counter:B?decrement=9")
                .to("mock:out");

            from("direct:in-3")
                .setHeader(HEADER_COUNTER_INCREMENT, constant(417L))
                .to("micrometer:counter:C")
                .to("mock:out");

            from("direct:in-4")
                .to("micrometer:counter:D?increment=${body.length}&tags=a=${body.length}")
                .to("mock:out");
        }
    });
    return camelctx;
}
 
Example 3
Source File: MetricsIntegrationTest.java    From wildfly-camel with Apache License 2.0 5 votes vote down vote up
@Test
public void testMetricsJsonSerialization() throws Exception {
    SimpleRegistry registry = new SimpleRegistry();
    MetricRegistry metricRegistry = new MetricRegistry();
    registry.bind("metricRegistry", metricRegistry);

    MetricsMessageHistoryFactory messageHistoryFactory = new MetricsMessageHistoryFactory();
    messageHistoryFactory.setMetricsRegistry(metricRegistry);

    CamelContext camelctx = new DefaultCamelContext(registry);
    camelctx.setMessageHistoryFactory(messageHistoryFactory);
    camelctx.addRoutes(new RouteBuilder() {
        @Override
        public void configure() throws Exception {
            from("direct:start")
            .to("metrics:counter:simple.counter?increment=5");
        }
    });

    camelctx.start();
    try {
        MetricsMessageHistoryService service = camelctx.hasService(MetricsMessageHistoryService.class);
        String json = service.dumpStatisticsAsJson();
        Assert.assertTrue(json.contains("\"gauges\":{},\"counters\":{},\"histograms\":{},\"meters\":{},\"timers\":{}"));
    } finally {
        camelctx.close();
    }
}