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


我想使用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]

如果我从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>

豆看起来像: -

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();
    }
  }
}

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


2388
2017-11-16 10:28


起源



答案:


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

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


5
2017-11-18 11:59



谢谢。我将startupOrder =“100”添加到直接路由,将“200”添加到发送给它的那个并且它完美地工作。 - Jeremy Gooch
我在配置路由之前设置了生产者模板并启动了camel上下文。顺序是configure route - camel context start - Producer Template配置 - Jobin Thomas


答案:


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

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


5
2017-11-18 11:59



谢谢。我将startupOrder =“100”添加到直接路由,将“200”添加到发送给它的那个并且它完美地工作。 - Jeremy Gooch
我在配置路由之前设置了生产者模板并启动了camel上下文。顺序是configure route - camel context start - Producer Template配置 - Jobin Thomas


根据您的设置,它可能还取决于 CamelContext 你已经接了。我得到了相同的错误消息,因为我正在另一个路径上发送消息 CamelContext 比我实际使用的那个。

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


8
2017-11-04 15:14



我有类似的问题。我忘了将@Component标头添加到RouteBuilder类,这意味着Spring没有创建该类的实例。 - Phyxx


对于其他人来说,此错误也可能是由尚未部署的依赖项的OSGI错误引起的。


0
2018-04-28 21:54





派对有点晚了但是当我有两个单独的蓝图文件时,这个错误发生在我身上,一个用于正常运行,另一个用于测试。在我的测试中,我指的是测试蓝图,但注意到正常的一个也是自动启动的,这导致了错误。

在文档中 http://camel.apache.org/blueprint-testing.html 它说你可以禁用某些捆绑启动。这对我来说很有帮助。


0
2018-05-18 08:19