Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Link to maven wiki for creating components

...

  • write a POJO which implements the Component interface. The simplest approach is just to derive from DefaultComponent
  • to support auto-discovery of your component add a file to META-INF/services/org/apache/camel/component/FOO where FOO is the URI scheme for your component and any related endpoints created on the fly. The latter file should contain the definition of the component class. For example if your component is implemented by the com.example.CustomComponent class, the service file should contain the following line - class=com.example.CustomComponent .

Users can then either explicitly create your component, configure it and register with a CamelContext or users can use a URI which auto-creates your component.

...

When implementing an Endpoint you typically may implement one or more of the following methods

Typically you just derive from DefaultEndpoint and implement the createProducer() and / or createConsumer() methods. The createPollingConsumer() method will be created by default for you in the DefaultEndpoint class.

If your endpoint is a polling-centric component you can derive from DefaultPollingEndpoint and then implement createPollingConsumer(); the createConsumer() method will be created for you which avoids you having to write any polling code.

Annotating your Endpoint

As of Camel 2.12 if you want to benefit from the automatic generation of HTML documentation for all the parameters on your endpoint as part of the maven site reports, you need to annotate your Endpoint's parameters.

So this means you add a @UriEndpoint annotation to your Endpoint class and then annotate each parameter you wish to be configured via the URI configuration mechanism with @UriParam (or @UriParams for nested configuration objects).

In addition its recommended that your Component implementation inherit from the UriEndpointComponent base class as that means your Component will automatically generate better metadata for the ComponentConfiguration API.

Refer to the Endpoint Annotations guide for details.

Using a Processor

If you are writing a simple endpoint which just processes messages in some way, you can just implement a Processor and use that to create an endpoint.

...

The parameters is provided by Camel in the createEndpoint method from DefaultComponent:

Code Block

protected abstract Endpoint<E> createEndpoint(String uri, String remaining, Map parameters)

The code is an example from the SEDA component that removes the size parameter:

Code Block

    public BlockingQueue<Exchange> createQueue(String uri, Map parameters) {
        int size = 1000;
        Object value = parameters.remove("size");
        if (value != null) {
            Integer i = convertTo(Integer.class, value);
            if (i != null) {
                size = i;
            }
        }
        return new LinkedBlockingQueue<Exchange>(size);
    }

...