使用aws-sqs骆驼组件中的SQSClient连接到ElasticMQ sqs服务器

时间:2019-07-13 17:05:53

标签: apache-camel amazon-sqs elastic-mq

我正在尝试使用Amazon SQS进行集成测试。我有一个中间件应用程序,该应用程序正在侦听外部SQS队列并处理消息。为了进行集成测试,我无法使用外部SQS队列,因此我尝试使用Elastic MQ服务器创建SQS队列。服务器正在运行。

[main] INFO org.elasticmq.rest.sqs.TheSQSRestServerBuilder-启动的SQS休息服务器,绑定地址127.0.0.1:9300,可见服务器地址http://localhost:9324

我可以使用在Integration测试类中创建的sqs客户端发送和接收消息。但是原始应用程序无法连接到SQS。

使用以下代码创建服务器:

  SQSRestServerBuilder.withPort(9324).withInterface("127.0.0.1").start();
    String endpoint = "http://127.0.0.1:9300";
    String region = "us-east-1";
    String accessKey = "x";
    String secretKey = "x";
    AmazonSQS client = AmazonSQSClientBuilder.standard()
        .withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials(accessKey, secretKey)))
        .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endpoint, region))
        .build();
    client.createQueue("queueName");`

能够使用

发送消息

sqsClient.sendMessage(“ http://localhost:9300/queue/queueName”,json); ReceiveMessageResult recieveMessage = sqsClient.receiveMessage(“ http://localhost:9300/queue/queueName”); Listlist = recieveMessage.getMessages();

但是骆驼路线抛出“连接被拒绝”错误。

from(“ aws-sqs:// queueName?amazonSQSClient =#amazonSQSClient”).routeId(Constants.SQS_CONSUMER_ROUTE_ID)         .log(“ MESSAGE:SQS_MESSAGE_RECEIVED”)

amazonSQSClient configuration is 
String endpoint = "http://127.0.0.1:9324";
String region = "us-east-1";
String accessKey = "x";
String secretKey = "x";

我认为应用程序将能够使用该配置连接到ElasticMQ服务器并能够从SQS队列订阅消息

0 个答案:

没有答案