如何将 Spring 云与 ElasticMQ 一起使用

How to use Spring Cloud with ElasticMQ

我们想使用 Spring Cloud for AWS SQS,但在我看来它只允许我们指定区域。我们可以伪造它以便它使用 ElasticMQ(例如在 localhost:9320 上)吗?如果不编辑主机文件并将证书放在 localhost

上,我找不到一种简单的方法来执行此操作

经过一番研究,我找到了一个方法。 您应该在注入 AmazonSQS 实例后设置一个端点,以覆盖已经设置的端点,如下所示:

@Autowired
public void setAmazonSqs(AmazonSQS amazonSqs)
{
    this.amazonSqs = amazonSqs;

    // use elasticMQ if spring default profile is used; no active profiles
    if (environment.getActiveProfiles().length == 0)
    {
        amazonSqs.setEndpoint("http://localhost:9320");
    }
}

是否要使用取决于您QueueMessagingTemplate,无论如何您应该修改注入的 AmazonSQS 实例。