首页 > 解决方案 > 测试 Camel 应用程序时如何模拟 Amazon SQS 终端节点

问题描述

我正在编写一个使用 Camel 来监听 SQS 队列的 Spring Boot 应用程序。路线定义:

from("aws-sqs://my-s3-notification-queue" +
    "?amazonSQSClient=#sqsClient" +
    "&deleteAfterRead=false")
    .unmarshal().json(JsonLibrary.Jackson, S3EventNotification.class)
    .bean(s3NotificationHandler);

sqsClient@Bean@Configuration文件中定义为 a 。

在运行测试时,我想模拟 SQS 端点,这样我就不会真正连接到 AWS。我该怎么做呢?我试过写我的测试,比如

@RunWith(CamelSpringBootRunner.class)
@SpringBootTest
@MockEndpoints
public class ApplicationTests {

    @Test
    public void contextLoads() {
    }

}

如果我正确阅读文档,这应该可以工作,但它仍会尝试连接到 AWS。我错过了什么?

标签: javaspring-bootjunitapache-camel

解决方案


您可以使用Localstack 使用它,您可以从本地系统模拟多个 AWS 服务,而无需连接 AWS。


推荐阅读