2017-04-13 39 views
-1

对于某些测试客户端,我使用yopa库模仿本地aws。为了发布消息的主题,然后将其接收到队列我这样做骆驼路线发布消息的主题,并从队列中接收它们

AmazonSQS amazonSQSClient = AmazonSQSClientBuilder.standard() 
      .withCredentials(new AWSCredentialsProvider() { 
       @Override 
       public AWSCredentials getCredentials() { return null; } 

       @Override 
       public void refresh() { } 
      }) 
      .withEndpointConfiguration(new EndpointConfiguration("http://localhost:47195", "yopa-local")) // local stub 
      .build(); 
    AmazonSNS amazonSNSClient = AmazonSNSClientBuilder.standard() 
      .withCredentials(new AWSCredentialsProvider() { 
       @Override 
       public AWSCredentials getCredentials() { return null; } 

       @Override 
       public void refresh() { } 
      }) 
      .withEndpointConfiguration(new EndpointConfiguration("http://localhost:47196", "yopa-local")) // local stub 
      .build(); 
    amazonSNSClient.publish("arn:aws:sns:yopa-local:000000000000:test-topic-with-subscriptions", 
      "This is my message"); 
    ReceiveMessageResult message = 
      amazonSQSClient.receiveMessage("http://localhost:47195/queue/test-subscribed-queue-standard"); 
    System.out.println("Number of recievied messages: " + message.getMessages().get(0)); 

它工作正常。

但是,如何使用apache camelspring来实现该流程?

当我创建这样

<routeContext id="myRoute" xmlns="http://camel.apache.org/schema/spring"> 
    <route id="publish.route"> 
     <from uri="bean:snsPublisher?method=publish({{sns.topic}}, ${body})"/> 
     <to uri="arn:aws:sns:yopa-local:000000000000:test-topic-with-subscriptions"/> 
     <onException redeliveryPolicyRef="redeliveryPolicy"> 
      <exception>java.lang.Exception</exception> 
      <handled> 
       <constant>{{camel.handle.exception}}</constant> 
      </handled> 
     </onException> 
    </route> 
</routeContext> 

随着publisher豆路由

public class SnsPublisher extends SnsClient implements IPublisher<String> { 
    @Override 
    public void publish(String topic, String message) { 
     try { 
      PublishResult publishResult = getAmazonSNSClient().publish("arn:aws:sns:yopa-local:000000000000:test-topic-with-subscriptions", message); 
     } catch (AmazonSNSException exception) { 
     } 
    } 
} 

SnsClient是类,它提供相同的AmazonSNS对象作为前面的例子。)

即使在我得到的应用程序开始

Caused by: org.apache.camel.ResolveEndpointFailedException: 
Failed to resolve endpoint: arn://aws:sns:yopa-local:000000000000:test-topic-with-subscriptions due to: No component found with scheme: arn 

org.apache.camel.RuntimeCamelException: org.apache.camel.FailedToCreateRouteException: 
Failed to create route publish.route at: >>> To[arn:aws:sns:yopa-local:000000000000:test-topic with-subscriptions] <<< in route: Route(publish.route [[From[bean:snsPublisher... because of Failed to resolve endpoint: arn://aws:sns:yopa-local:000000000000:test-topic-with-subscriptions due to: No component found with scheme: arn 

回答

1
No component found with scheme: arn 

这个说“ARN”不是某个部件名称骆驼可以识别。

骆驼的url以一个骆驼组件的名字开头,它应该首先定义。

例如,如果连接到activemq,您应该实现一个JmsComponent或ActiveMQComponent,名称为“amq”,然后您可以在camel uri中连接到“amq:xxxx”。

我从来没有使用aws,所以我不能给你非常具体的建议。我可以告诉你的是,你需要实现一个“arn”组件,也许它存在于某个第三方库中,或者你需要编写自己的骆驼组件类。