Camel how to add something to registry - with java, in general

后端 未结 3 882
逝去的感伤
逝去的感伤 2020-12-20 16:39

sometimes I have to add an object to camel registry (of course with java). In most cases it is a dataSource .

My problem is I can\'t figure out a general working way

3条回答
  •  离开以前
    2020-12-20 17:02

    Here is one way of adding stuff to the registry in a RouteBuilder class. Below I am adding a TCPServerInitializerFactory which will be used later on. I always use the camel-blueprint archetype but create routes using java dsl. This works fine for me.

    TCPServerInitializerFactory serverFactory = new TCPServerInitializerFactory(null);
    final CamelContext camelContext = getContext();
            final org.apache.camel.impl.SimpleRegistry registry = new org.apache.camel.impl.SimpleRegistry();
            final org.apache.camel.impl.CompositeRegistry compositeRegistry = new org.apache.camel.impl.CompositeRegistry();
            compositeRegistry.addRegistry(camelContext.getRegistry());
            compositeRegistry.addRegistry(registry);
            ((org.apache.camel.impl.DefaultCamelContext) camelContext).setRegistry(compositeRegistry);
        registry.put("spf", serverFactory);
    

提交回复
热议问题