我正在编写一个使用 Camel 来监听 SQS 队列的 Spring Boot 应用程序。路线定义:
from("aws-sqs://my-s3-notification-queue" +
"?amazonSQSClient=#sqsClient" +
"&deleteAfterRead=false")
.unmarshal().json(JsonLibrary.Jackson, S3EventNotification.class)
.bean(s3NotificationHandler);
sqsClient
被定义为 @Configuration
文件中的 @Bean
。
运行测试时,我想模拟 SQS 端点,这样我就不会实际连接到 AWS。我该怎么做呢?我试过像这样编写测试
@RunWith(CamelSpringBootRunner.class)
@SpringBootTest
@MockEndpoints
public class ApplicationTests {
@Test
public void contextLoads() {
}
}
如果我正确阅读文档,这应该可以工作,但它仍会尝试连接到 AWS。我错过了什么?
最佳答案
您可以使用 Localstack 使用它,您可以从本地系统模拟多个 AWS 服务,而无需连接 AWS。
关于java - 测试 Camel 应用程序时如何模拟 Amazon SQS 端点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51045131/