Search code examples
xmlapache-camelcustom-tags

How to add custom XML tag to Apache Camel configuration


I need to implement something like this:

<from uri="direct:pewpew" />
<doMegaWork status="Busy" message="Don't push on me!">
<to uri="direct:next"/>

I still did not find the same problem (much less a solution) on Google. Maybe someone knows how to do this?


Solution

  • Custom tags and/or namespaces are not (yet) supported by Camel (and perhaps it will never be?).

    I see following different solutions to encapsulate reusable processing steps:

    • Write a separate reusable route. I guess this is the simplest solution and the standard way to do it.
    • Write a processor/bean/service that encapsulates the whole processing.
    • Include a full context into your route using the Camel context component. First, you add a Camel context to the registry:

      registry.bind("accounts", myAccountContext);
      

      Then you use the context in your route:

      <from uri="accounts:invoice"/>
      
    • Write a component as described here.