Question

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.

Was it helpful?

Solution 2

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.

OTHER TIPS

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

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

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.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top