Apache Camel Endpoint injection to direct route "No consumers available on endpoint"
Asked Answered
C

5

16

I want to use Camel to take a message from ActiveMQ and then, based on the message contents (a protobuf), send one or more messages to Twitter. I've written a bean that is called from within a route and which uses injection to send multiple messages to a "direct:xyz" endpoint.

However, Camel is complaining at runtime that:

2012-11-16 09:56:33,376 | WARN  | ication.twitter] | DirectProducer                   | 160 - org.apache.camel.camel-core - 2.10.2 | No consumers available on endpoint: Endpoint[direct://twitter] to process: Exchange[Message: hello world]

If I instead inject directly to the Twitter endpoint from within the bean, it works fine. However, in order to ease testing, simplify configuration etc, I'd like to keep the actual Twitter config separate, hence wanting to send to a separate route.

The camel context config looks like:-

<camelContext id="NotificationTwitter"
    trace="false" xmlns="http://camel.apache.org/schema/blueprint">
    <dataFormats>
        <protobuf id="notificationProto" instanceClass="org.abc.schemas.protobuf.NotificationDef$NotificationMsg" />
    </dataFormats>

    <route id="TwitterPreparation">
        <from uri="activemq:notification.twitter" />
        <unmarshal ref="notificationProto" />
        <log logName="abc" loggingLevel="INFO"
            message="Twitter request received: ${body}" />
        <bean ref="NotificationTweeter" method="createTweets" />
    </route>

    <route id="Twitter">
        <from uri="direct:twitter" />
        <log logName="abc" loggingLevel="INFO"
            message="Tweeting: ${body}" />
        <to uri="twitter://timeline/user?consumerKey=itsasecret&amp;consumerSecret=itsasecret&amp;accessToken=itsasecret&amp;accessTokenSecret=itsasecret" />
    </route>
</camelContext>

The bean looks like:-

public class NotificationTweeter {

  @EndpointInject(uri = "direct:twitter")
  private ProducerTemplate producerTemplate;

  public void createTweets(NotificationMsg notification) {

    String tweet = notification.getMessageDetail().getTitle();

    try {
      // only send tweets where the notification message contains the Twitter mechanism
      for (MechanismMsg mechanism : notification.getMechanismList()) {
        if (mechanism.getType() == MechanismTypeEnum.TWITTER) {

          // Cycle round the recipients
          for (RecipientMsg recipient : mechanism.getRecipientList()) {
            tweet = "@" + recipient.getIdentifier() + " " + tweet;

            producerTemplate.sendBody(tweet);
          }

          // TODO exceptions if no recipients found, etc
        }
      }
    } catch (Exception ex) {
      ex.printStackTrace();
    }
  }
}

I've had this problem in other routes (it's certainly not related to the Twitter feature) but have just worked around it. This time, however, I'd like to actually understand what the issue is! Any help gratefully received, thanks.

Counterfactual answered 16/11, 2012 at 10:28 Comment(0)
K
8

It sounds like a problem with the startup ordering of your routes. See more detail here http://camel.apache.org/configuring-route-startup-ordering-and-autostartup.html

You can configure the "direct" route to start before the other route, then that issue should be resolved.

Kiowa answered 18/11, 2012 at 11:59 Comment(2)
Thanks. I added startupOrder="100" to the direct route and "200" to the one that sends to it and it worked perfectly.Counterfactual
I was setting producer template and starting camel context before configuring the route. The order is configure route - camel context start - Producer Template configurationMagi
M
9

According to your setup, it might also depend on the CamelContext you have picked up. I got the same error message because I was sending messages on a route that existed in another CamelContext than the one I actually was using.

(Although the previous answer was already accepted, this might be the working solution for other people searching for that error message.)

Mothering answered 4/11, 2013 at 15:14 Comment(1)
I had a similar problem. I forgot to add the @Component header to the RouteBuilder class, which meant Spring was not creating an instance of the class.Villous
K
8

It sounds like a problem with the startup ordering of your routes. See more detail here http://camel.apache.org/configuring-route-startup-ordering-and-autostartup.html

You can configure the "direct" route to start before the other route, then that issue should be resolved.

Kiowa answered 18/11, 2012 at 11:59 Comment(2)
Thanks. I added startupOrder="100" to the direct route and "200" to the one that sends to it and it worked perfectly.Counterfactual
I was setting producer template and starting camel context before configuring the route. The order is configure route - camel context start - Producer Template configurationMagi
D
1

For others coming here, this error can also be caused by an OSGI error for a dependency that has not been deployed.

Deed answered 28/4, 2015 at 21:54 Comment(0)
C
1

A bit late to the party but this error happened to me when I had two separate blueprint files, one for normal running and one for test. In my test I was referring to the test blueprint but noticed that the normal one was also automatically started which caused errors.

In the documentation http://camel.apache.org/blueprint-testing.html it says you can disable certain bundles from starting up. That helped me in my case.

Cognac answered 18/5, 2016 at 8:19 Comment(0)
J
0

This can also be caused by having a . in the route name. Replace my.Route.Name with myRouteName fixed the issue for me.

Jo answered 3/4, 2019 at 7:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.