如何使用代理设置构建AmazonSQS

时间:2018-04-03 16:18:48

标签: java amazon-web-services aws-sdk

我需要创建一个通过特定代理(不使用jvm默认值)的AmazonSQS。我想使用所有标准默认值,只更改代理。有没有简单的方法来设置代理信息?到目前为止,这就是我所拥有的。

AmazonSQSClientBuilder builder = AmazonSQSClientBuilder.standard();
AmazonSQS sqsClient = builder.withClientConfiguration(
    builder.getClientConfiguration()
    .withProxyHost("hostname")
    .withProxyPort(port)
    .withNonProxyHosts("no proxy hosts"))
    .build()

这导致builder.getClientConfiguration().withProxyHost("hostname")上的NPE。如何在构建器中将客户端配置设置为具有默认值的配置,然后设置代理信息?

1 个答案:

答案 0 :(得分:1)

builder没有配置集。使用PredefinedClientConfigurations修复此问题。

AmazonSQSClientBuilder builder = AmazonSQSClientBuilder.standard();
AmazonSQS sqsClient = builder.withClientConfiguration(
    PredefinedClientConfigurations.defaultConfig()
    .withProxyHost("hostname")
    .withProxyPort(port)
    .withNonProxyHosts("no proxy hosts"))
    .build()

这将创建一个包含所有默认设置和代理主机设置的AmazonSQS。