简体   繁体   中英

Adding Apache Camel custom component/endpoint in a Spring application

I'm trying to implement a custom endpoint in a Spring Boot application.

Goal is to use routes as: from("...").process("...").to("my:...");

Now, I have 3 classes: a DefaultConsumer, a DefaultEndpoint, a DefaultComponent:

package com.my.endpoint;

import org.apache.camel.Consumer;
import org.apache.camel.Processor;
import org.apache.camel.Producer;
import org.apache.camel.support.DefaultEndpoint;

public class MyEndpoint extends DefaultEndpoint {

    public MyEndpoint(String uri, MyComponent myComponent) {

    }
    ...
}

package com.my.endpoint;

import org.apache.camel.Endpoint;
import org.apache.camel.Processor;
import org.apache.camel.support.DefaultConsumer;

public class MyConsumer extends DefaultConsumer {

    public MyConsumer(Endpoint endpoint, Processor processor) {

        super(endpoint, processor);
    }
}

package com.my.endpoint;

import org.apache.camel.CamelContext;
import org.apache.camel.Endpoint;
import org.apache.camel.spi.annotations.Component;
import org.apache.camel.support.DefaultComponent;

import java.util.Map;

@Component("my")
public class MyComponent extends DefaultComponent {

    public MyComponent(CamelContext camelContext) {

        super(camelContext);
    }
    ...
}

Now: how can I register?

In a Spring configuration class, I have:

  @Override
  public void configure() throws Exception {

        camelContext.addComponent("my", new MyComponent(camelContext));

But is not working:

    Caused by: org.apache.camel.NoSuchEndpointException: No endpoint could be found for: my, please check your classpath contains the needed Camel component jar.

So, I added the META-INF file in services/org/apache/camel/component/my:

class=com.my.endpoint.MyComponent

But also this, is not working.

There is no complete tutorial on how to implement this.

Any help?

Note: I'm trying to implement an Endpoint because I need to integrate my systems using my data types. I tried using Transformer but failed because of this: Set a custom DataType in Apache Camel Processor

Before, I tried using data type converter, but failed because of this (marked duplicate because people are too lazy to really understand questions): Enforce type conversion on Rest consumer in Apache Camel

I've FULLY read "Apache Camel In Action, Second Edition" but, at the moment, I can't continue with my project because of?

This is because custom component must be annotated by @UriEndpoint annotation.

Another way to solve this problem: Set EndpointUri via Constructor or by implementing createEndpointUri() in MyEndpoint.

So easiest way might be changing your constructor to:

public MyEndpoint(String uri, MyComponent myComponent) {
 super(uri, myComponent);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM