2012-11-16 164 views
10

我想使用Camel从ActiveMQ中接收消息,然后根据消息内容(protobuf)向Twitter发送一条或多条消息。我写了一个从路由中调用的bean,它使用注入将多个消息发送到“direct:xyz”端点。Apache 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配置不同,因此希望发送到单独的路由。

骆驼方面的配置是这样的: -

bean的样子: -

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

我已经在其他途径(这个问题,肯定不是相关的Twitter功能),但刚刚解决它。然而,这次我真的想明白这个问题是什么!感激地收到了任何帮助,谢谢。

回答

5

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

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

+0

谢谢。我将startupOrder =“100”添加到直接路由,将“200”添加到发送给它的那个,并且完美运行。 –

+0

在配置路由之前,我正在设置生产者模板并启动骆驼上下文。顺序是配置路由 - 驼峰上下文开始 - 生产者模板配置 –

7

根据你的设置,它也可能取决于你拿起的CamelContext。我得到了同样的错误信息,因为我在另一个CamelContext中存在的路线上发送的消息比我实际使用的路线中的消息多。

(虽然以前的答案已经被接受,这可能是为其他人寻找该错误信息的工作溶液中。)

+0

我有一个类似的问题。我忘了将@Component头添加到RouteBuilder类中,这意味着Spring不会创建该类的实例。 – Phyxx

0

对于其他人来到这里,这个错误也可以通过为一个OSGI错误引起的尚未部署的依赖关系。

0

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

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