Spring cloud 问题测试SpringCloudSQS侦听器 环境 弹簧靴:1.5.13.1释放 云:Edgware.SR3 云AWS:1.2.2.1版本 爪哇8 OSX 10.13.4 问题

Spring cloud 问题测试SpringCloudSQS侦听器 环境 弹簧靴:1.5.13.1释放 云:Edgware.SR3 云AWS:1.2.2.1版本 爪哇8 OSX 10.13.4 问题,spring-cloud,spring-cloud-aws,Spring Cloud,Spring Cloud Aws,我正在尝试为SQS编写一个集成测试 我有一个本地运行的docker容器,其中SQS在TCP/4576 在我的测试代码中,我定义了一个端点设置为本地4576的SQS客户机,它可以成功连接并创建队列、发送消息和删除队列。我还可以使用SQS客户端来接收消息并拾取我发送的消息 我的问题是,如果我删除手动接收消息的代码以允许另一个组件获取消息,那么似乎什么都没有发生。我有一个弹簧组件,注释如下: 听众 试验 在测试日志中,我看到: o、 s.c.a.m.listener.QueueMessageHandl

我正在尝试为SQS编写一个集成测试

我有一个本地运行的docker容器,其中SQS在
TCP/4576

在我的测试代码中,我定义了一个端点设置为本地4576的SQS客户机,它可以成功连接并创建队列、发送消息和删除队列。我还可以使用SQS客户端来接收消息并拾取我发送的消息

我的问题是,如果我删除手动接收消息的代码以允许另一个组件获取消息,那么似乎什么都没有发生。我有一个弹簧组件,注释如下:

听众 试验 在测试日志中,我看到:

o、 s.c.a.m.listener.QueueMessageHandler:在MyListener类上找到1个消息处理程序方法:{public void MyListener.receive(MyMsg)=org.springframework.cloud.aws.messaging.listener.QueueMessageHandler$MappingInformation@1cd4082a} 2018-05-31 22:50:39.582信息16329--

o、 s.c.a.m.listener.QueueMessageHandler:映射的“org.springframework.cloud.aws.messaging.listener.QueueMessageHandler”$MappingInformation@1cd4082a“转到公共void MyListener.receive(MyMsg)

其次是:

isRunning:对

是的

IsRuningQueuee:错误

得到消息:1

这表明,在发送消息与容器没有拾取消息之间的30秒暂停时间内,当我手动轮询消息时,它就在队列中,我可以使用它

我的问题是,为什么侦听器没有被调用,为什么
isrunningunqueue:false
行表示该队列没有自动启动

请注意,我还尝试将自己的
SimpleMessageListenerContainer
bean的autostart显式设置为true(默认设置),但没有观察到行为的变化。我认为由
@EnableSqs
设置的
org.springframework.cloud.aws.messaging.config.annotation.sqscoconfiguration#simpleMessageListenerContainer
应该配置一个自动启动的
simpleMessageListenerContainer
,它应该轮询我的消息

我还设置了

logging.level.org.apache.http=DEBUG
logging.level.org.springframework.cloud=DEBUG

在我的测试属性中,可以看到HTTP调用创建队列、发送消息和删除等,但没有要接收的HTTP调用(除了测试结束时的手动调用)

经过一番修补后,我发现了这一点

即使简单消息容器工厂被设置为非自动启动,它似乎也会进行初始化,这涉及到确定队列是否存在

在本例中,队列是在我的测试中用setup方法创建的——但遗憾的是,这是在spring上下文设置之后创建的,这意味着发生了异常

我通过简单地将队列创建移动到SQS客户机的上下文创建(在创建消息容器之前发生)来解决这个问题。i、 e:

@RunWith(SpringRunner.class)
@SpringBootTest(properties = "spring.profiles.active=test")
public class MyTest {

    @Autowired
    private AmazonSQSAsync amazonSQS;

    @Autowired
    private SimpleMessageListenerContainer container;

    private String queueUrl;

    @Before
    public void setUp() {
        queueUrl = amazonSQS.createQueue("my_queue").getQueueUrl();
    }

    @After
    public void tearDown() {
        amazonSQS.deleteQueue(queueUrl);
    }

    @Test
    public void name() throws InterruptedException {
        amazonSQS.sendMessage(new SendMessageRequest(queueUrl, "hello"));
        System.out.println("isRunning:" + container.isRunning());
        System.out.println("isActive:" + container.isActive());
        System.out.println("isRunningOnQueue:" + container.isRunning("my_queue"));
        Thread.sleep(30_000);
        System.out.println("GOT MESSAGE: " + amazonSQS.receiveMessage(queueUrl).getMessages().size());
    }

    @TestConfiguration
    @EnableSqs
    public static class SQSConfiguration {

        @Primary
        @Bean(destroyMethod = "shutdown")
        public AmazonSQSAsync amazonSQS() {
            final AwsClientBuilder.EndpointConfiguration endpoint = new AwsClientBuilder.EndpointConfiguration("http://127.0.0.1:4576", "eu-west-1");
            return new AmazonSQSBufferedAsyncClient(AmazonSQSAsyncClientBuilder
                    .standard()
                    .withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials("key", "secret")))
                    .withEndpointConfiguration(endpoint)
                    .build());
        }
    }
}
logging.level.org.apache.http=DEBUG
logging.level.org.springframework.cloud=DEBUG
@Bean(destroyMethod = "shutdown")
        public AmazonSQSAsync amazonSQS() {
            final AwsClientBuilder.EndpointConfiguration endpoint = new AwsClientBuilder.EndpointConfiguration("http://localhost:4576", "eu-west-1");
            final AmazonSQSBufferedAsyncClient client = new AmazonSQSBufferedAsyncClient(AmazonSQSAsyncClientBuilder
                    .standard()
                    .withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials("dummyKey", "dummySecret")))
                    .withEndpointConfiguration(endpoint)
                    .build());
            client.createQueue("test-queue");
            return client;
        }