Apache Camel Endpoint注入直接路由"端点上没有可用的消费者"

Jer*_*och 14 apache-camel endpoint blueprint

我想使用Camel从ActiveMQ接收消息,然后根据消息内容(protobuf)向Twitter发送一条或多条消息.我编写了一个从路由中调用的bean,它使用注入将多个消息发送到"direct:xyz"端点.

但是,Camel在运行时抱怨:

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]
Run Code Online (Sandbox Code Playgroud)

如果我从bean内直接注入Twitter端点,它可以正常工作.但是,为了便于测试,简化配置等,我想将实际的Twitter配置分开,因此希望发送到单独的路由.

驼峰上下文配置如下: -

<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>
Run Code Online (Sandbox Code Playgroud)

豆看起来像: -

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();
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

我在其他路线上遇到过这个问题(它肯定与推特功能没有关系),但刚刚解决了这个问题.但是,这一次,我想真正了解问题所在!任何帮助感激不尽,谢谢.

ben*_*min 9

根据您的设置,它可能还取决于CamelContext您已经选择.我得到了相同的错误消息,因为我在一条路径上发送消息,而该路由存在于CamelContext我实际使用的路径之外.

(虽然之前的答案已经被接受,但这可能是搜索该错误消息的其他人的工作解决方案.)


Cla*_*sen 7

这听起来像是路线启动顺序的问题.在此处查看更多详细信息http://camel.apache.org/configuring-route-startup-ordering-and-autostartup.html

您可以将"直接"路由配置为在其他路由之前启动,然后应该解决该问题.