2017-04-13 76 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」組件,也許它存在於某個第三方庫中,或者你需要編寫自己的駱駝組件類。