我想使用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&consumerSecret=itsasecret&accessToken=itsasecret&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();
    }
  }
}
我在其他路线上遇到过这个问题(肯定与推特功能没有关系),但刚刚解决了这个问题。但是,这一次,我想真正了解问题所在!任何帮助感激不尽,谢谢。