简体   繁体   English

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

[英]Apache Camel Endpoint injection to direct route “No consumers available on endpoint”

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. 我想使用Camel从ActiveMQ接收消息,然后根据消息内容(protobuf)向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. 我编写了一个从路由中调用的bean,它使用注入将多个消息发送到“direct:xyz”端点。

However, Camel is complaining at runtime that: 但是,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]

If I instead inject directly to the Twitter endpoint from within the bean, it works fine. 如果我从bean内直接注入Twitter端点,它可以正常工作。 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. 但是,为了便于测试,简化配置等,我想将实际的Twitter配置分开,因此希望发送到单独的路由。

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. 任何帮助感激不尽,谢谢。

According to your setup, it might also depend on the CamelContext you have picked up. 根据您的设置,它可能还取决于您拾取的CamelContext 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. 我得到了相同的错误消息,因为我在另一个CamelContext中存在的路径上发送消息CamelContext不是我实际使用的路径。

(Although the previous answer was already accepted, this might be the working solution for other people searching for that error message.) (虽然之前的答案已经被接受,但这可能是搜索该错误消息的其他人的工作解决方案。)

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 在此处查看更多详细信息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. 您可以将“直接”路由配置为在其他路由之前启动,然后应该解决该问题。

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

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. http://camel.apache.org/blueprint-testing.html文档中,它说您可以禁用某些捆绑包启动。 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. 更换my.Route.NamemyRouteName固定我的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Apache Camel-JUNIT测试中的终结点上没有可用的使用者 - Apache Camel - No Consumers available on endpoint in JUNIT test 骆驼-DirectConsumerNotAvailableException端点上没有可用的使用者 - Camel - DirectConsumerNotAvailableException No consumers available on endpoint Akka Camel:终结点上没有可用的消费者 - Akka Camel: No consumers available on endpoint 使用 Apache Camel 进行端点注入 - Endpoint Injection with Apache Camel 骆驼浓缩错误:终结点上没有消费者:终结点 - Camel Enrichment error: No consumers available on endpoint: Endpoint 端点上没有可用的消费者:Endpoint[direct://LookUpRoute] - No consumers available on endpoint: Endpoint[direct://LookUpRoute] Apache Camel - DirectConsumerNotAvailableException:端点上没有可用的消费者。 交换[] - Apache Camel - DirectConsumerNotAvailableException: No consumers available on endpoint. Exchange[] Apache Camel Spring Javaconfig单元测试端点上没有使用者 - Apache Camel Spring Javaconfig Unit Test No consumers available on endpoint Apache camel 2.16丰富-JUnit中的终结点上没有可用的使用者 - Apache camel 2.16 enrich - No consumers available on endpoint in JUnit 没有“到”端点的 Apache Camel 路由 - Apache Camel route with no "to" endpoint
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM