Search code examples
apache-camelspring-camel

Using Camel Endpoint DSL with @EndpointInject creating different endpoints


What is the proper way to use endpoint DSL and then reference the endpoint with ProducerTemplate? When creating a route and using endpoint DSL, it seems that Camel is creating a different uri for the endpoint. My EndpointRouteBuilder class:

@Component
public class MyRoutes extends EndpointRouteBuilder {

    @Override
    public void configure() throws Exception {
        from(seda("STATUS_ENDPOINT"))
        .routeId("stateChangeRoute")
        .to(activemq("topic:statusTopic"))
    }
}

and then injecting the endpoint to ProducerTemplate

@Component
public class StateChangePublisher {

    @EndpointInject(value="seda:STATUS_ENDPOINT")
    private ProducerTemplate producer;

    public void publish(String str) {
        try {
            producer.sendBody(str);
        } catch(CamelExecutionException e) {
            e.printStackTrace();
        }
    }
}

When camel starts, I see two entries in the log:

o.a.camel.component.seda.SedaEndpoint    : Endpoint seda:STATUS_ENDPOINT is using shared queue: seda:STATUS_ENDPOINT with size: 1000
o.a.camel.component.seda.SedaEndpoint    : Endpoint seda://STATUS_ENDPOINT is using shared queue: seda://STATUS_ENDPOINT with size: 1000

The queue eventually fills up and nothing gets delivered to the "to" endpoint. If I define the route without using the endpoint DSL method "seda()"

from("seda:STATUS_ENDPOINT")

then it works. Is this a bug or am I doing something wrong? I'm using camel 3.2.0 and


Solution

  • This was a bug in the endpoint dsl. Try upgrading to camel 3.3.0. I think it was fixed in the new release.

    https://issues.apache.org/jira/browse/CAMEL-14859