-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 camel
和spring
來實現該流程?
當我創建這樣
<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