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

Jeremy Gooch picture Jeremy Gooch · Nov 16, 2012 · Viewed 36.7k times · Source

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.

Answer

benjamin picture benjamin · Nov 4, 2013

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.)