Java 类com.amazonaws.services.sqs.AmazonSQSClientBuilder 实例源码

项目:log4j-aws-appenders    文件:SNSAppenderIntegrationTest.java   
/**
 *  Loads the test-specific Log4J configuration and resets the environment.
 */
public void setUp(String propertiesName)
throws Exception
{
    URL config = ClassLoader.getSystemResource(propertiesName);
    assertNotNull("missing configuration: " + propertiesName, config);

    LogManager.resetConfiguration();
    PropertyConfigurator.configure(config);

    localLogger = Logger.getLogger(getClass());

    runId = String.valueOf(System.currentTimeMillis());
    resourceName = "SNSAppenderIntegrationTest-" + runId;
    System.setProperty("SNSAppenderIntegrationTest.resourceName", resourceName);

    localSNSclient = AmazonSNSClientBuilder.defaultClient();
    localSQSclient = AmazonSQSClientBuilder.defaultClient();
}
项目:aws-doc-sdk-examples    文件:VisibilityTimeout.java   
public static void changeMessageVisibilityMultiple(
        String queue_url, int timeout)
{
    AmazonSQS sqs = AmazonSQSClientBuilder.defaultClient();

    List<ChangeMessageVisibilityBatchRequestEntry> entries =
        new ArrayList<ChangeMessageVisibilityBatchRequestEntry>();

    entries.add(new ChangeMessageVisibilityBatchRequestEntry(
                "unique_id_msg1",
                sqs.receiveMessage(queue_url)
                   .getMessages()
                   .get(0)
                   .getReceiptHandle())
            .withVisibilityTimeout(timeout));

    entries.add(new ChangeMessageVisibilityBatchRequestEntry(
                "unique_id_msg2",
                sqs.receiveMessage(queue_url)
                   .getMessages()
                   .get(0)
                   .getReceiptHandle())
            .withVisibilityTimeout(timeout + 200));

    sqs.changeMessageVisibilityBatch(queue_url, entries);
}
项目:para    文件:AWSQueueUtils.java   
/**
 * Returns a client instance for AWS SQS.
 * @return a client that talks to SQS
 */
public static AmazonSQS getClient() {
    if (sqsClient != null) {
        return sqsClient;
    }
    if (Config.IN_PRODUCTION) {
        sqsClient = AmazonSQSClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(
            new BasicAWSCredentials(Config.AWS_ACCESSKEY, Config.AWS_SECRETKEY))).
                withRegion(Config.AWS_REGION).build();
    } else {
        sqsClient = AmazonSQSClientBuilder.standard().
                withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials("x", "x"))).
                withEndpointConfiguration(new EndpointConfiguration(LOCAL_ENDPOINT, "")).build();
    }

    Para.addDestroyListener(new DestroyListener() {
        public void onDestroy() {
            sqsClient.shutdown();
        }
    });
    return sqsClient;
}
项目:webcrawler    文件:AppConfig.java   
@Bean
public SQSConnectionFactory sqsConnectionFactory() throws JMSException {

    return new SQSConnectionFactory(
            new ProviderConfiguration(),
            AmazonSQSClientBuilder.standard()
                    .withRegion(Regions.AP_SOUTHEAST_2)
                    .withCredentials(new ProfileCredentialsProvider(CREDENTIALS_PROVIDER))
    );
}
项目:rxjava2-aws    文件:AwsClients.java   
public static AmazonSQS createSqsClient(AWSCredentials credentials, ClientConfiguration cc, Regions region) {
    return AmazonSQSClientBuilder //
            .standard() //
            .withCredentials(new AWSStaticCredentialsProvider(credentials)) //
            .withRegion(region) //
            .build();
}
项目:aws-ski-resort    文件:QueueService.java   
private AmazonSQS initializeSqs() {
    BasicAWSCredentials awsCredentials = new BasicAWSCredentials(accessKey, secretyKey);
    AWSStaticCredentialsProvider provider = new AWSStaticCredentialsProvider(awsCredentials);

    return AmazonSQSClientBuilder.standard()
            .withCredentials(provider)
            .withRegion(Regions.US_EAST_2)
            .build();
}
项目:ratpack-sqs    文件:DefaultAmazonSQSProvider.java   
@Override
public AmazonSQS get(SqsModule.EndpointConfig config) {
    AmazonSQSClientBuilder builder = AmazonSQSClientBuilder.standard();
    builder.withCredentials(credentialsProvider);
    if (config.endpoint().isPresent()) {
        builder.withEndpointConfiguration(
            new AwsClientBuilder.EndpointConfiguration(config.getEndpoint(), config.getRegionName())
        );
    } else {
        builder.withRegion(Regions.fromName(config.getRegionName()));
    }
    return builder.build();
}
项目:thingsboard    文件:SqsPlugin.java   
private void init() {
    AWSCredentials awsCredentials = new BasicAWSCredentials(configuration.getAccessKeyId(), configuration.getSecretAccessKey());
    AmazonSQS sqs = AmazonSQSClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(awsCredentials))
            .withRegion(Regions.fromName(configuration.getRegion())).build();
    this.sqsMessageHandler = new SqsMessageHandler(sqs);

}
项目:thingsboard    文件:SqsDemoClient.java   
public static void main(String[] args) {
    log.info("Starting SQS Demo Clinent...");
    AWSCredentials awsCredentials = new BasicAWSCredentials(ACCESS_KEY_ID, SECRET_ACCESS_KEY);
    AmazonSQS sqs = AmazonSQSClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(awsCredentials))
            .withRegion(Regions.fromName(REGION)).build();
    SqsDemoClient client = new SqsDemoClient();
    client.pollMessages(sqs);
}
项目:aws-doc-sdk-examples    文件:VisibilityTimeout.java   
public static void changeMessageVisibilitySingle(
        String queue_url, int timeout)
{
    AmazonSQS sqs = AmazonSQSClientBuilder.defaultClient();

    // Get the receipt handle for the first message in the queue.
    String receipt = sqs.receiveMessage(queue_url)
                        .getMessages()
                        .get(0)
                        .getReceiptHandle();

    sqs.changeMessageVisibility(queue_url, receipt, timeout);
}
项目:aws-doc-sdk-examples    文件:VisibilityTimeout.java   
public static void main(String[] args)
{
    final String queue_name = "testQueue" + new Date().getTime();
    AmazonSQS sqs = AmazonSQSClientBuilder.defaultClient();

    // first, create a queue (unless it exists already)
    try {
        CreateQueueResult cq_result = sqs.createQueue(queue_name);
    } catch (AmazonSQSException e) {
        if (!e.getErrorCode().equals("QueueAlreadyExists")) {
            throw e;
        }
    }

    final String queue_url = sqs.getQueueUrl(queue_name).getQueueUrl();

    // Send some messages to the queue
    for (int i = 0; i < 20; i++) {
        sqs.sendMessage(queue_url, "This is message " + i);
    }

    // change visibility timeout (single)
    changeMessageVisibilitySingle(queue_url, 3600);

    // change visibility timeout (multiple)
    changeMessageVisibilityMultiple(queue_url, 2000);
}
项目:aws-doc-sdk-examples    文件:SendReceiveMessages.java   
public static void main(String[] args)
{
    final AmazonSQS sqs = AmazonSQSClientBuilder.defaultClient();

    try {
        CreateQueueResult create_result = sqs.createQueue(QUEUE_NAME);
    } catch (AmazonSQSException e) {
        if (!e.getErrorCode().equals("QueueAlreadyExists")) {
            throw e;
        }
    }

    String queueUrl = sqs.getQueueUrl(QUEUE_NAME).getQueueUrl();

    SendMessageRequest send_msg_request = new SendMessageRequest()
            .withQueueUrl(queueUrl)
            .withMessageBody("hello world")
            .withDelaySeconds(5);
    sqs.sendMessage(send_msg_request);


    // Send multiple messages to the queue
    SendMessageBatchRequest send_batch_request = new SendMessageBatchRequest()
            .withQueueUrl(queueUrl)
            .withEntries(
                    new SendMessageBatchRequestEntry(
                            "msg_1", "Hello from message 1"),
                    new SendMessageBatchRequestEntry(
                            "msg_2", "Hello from message 2")
                            .withDelaySeconds(10));
    sqs.sendMessageBatch(send_batch_request);

    // receive messages from the queue
    List<Message> messages = sqs.receiveMessage(queueUrl).getMessages();

    // delete messages from the queue
    for (Message m : messages) {
        sqs.deleteMessage(queueUrl, m.getReceiptHandle());
    }
}
项目:rxjava-aws    文件:AwsClients.java   
public static AmazonSQS createSqsClient(AWSCredentials credentials, ClientConfiguration cc, Regions region) {
    return AmazonSQSClientBuilder //
            .standard() //
            .withCredentials(new AWSStaticCredentialsProvider(credentials)) //
            .withRegion(region) //
            .build();
}
项目:graylog-plugin-aws    文件:CloudtrailSQSClient.java   
public CloudtrailSQSClient(Region region, String queueName, AWSAuthProvider authProvider, HttpUrl proxyUrl, ObjectMapper objectMapper) {
    AmazonSQSClientBuilder clientBuilder = AmazonSQSClientBuilder.standard().withRegion(region.getName()).withCredentials(authProvider);

    if (proxyUrl != null) {
        clientBuilder.withClientConfiguration(Proxy.forAWS(proxyUrl));
    }

    this.sqs = clientBuilder.build();

    this.queueName = queueName;
    this.objectMapper = objectMapper;
}
项目:aws-cloudtrail-processing-library    文件:AWSCloudTrailProcessingExecutor.java   
private void buildSqsClient() {
    if (sqsClient == null) {
        sqsClient = AmazonSQSClientBuilder.standard()
                .withCredentials(config.getAwsCredentialsProvider())
                .withRegion(config.getSqsRegion())
                .build();
    }
}
项目:amazon-sqs-java-messaging-lib    文件:SQSConnectionFactory.java   
public SQSConnectionFactory(ProviderConfiguration providerConfiguration, final AmazonSQSClientBuilder clientBuilder) {
    if (providerConfiguration == null) {
        throw new IllegalArgumentException("Provider configuration cannot be null");
    }
    if (clientBuilder == null) {
        throw new IllegalArgumentException("AmazonSQS client builder cannot be null");
    }
    this.providerConfiguration = providerConfiguration;
    this.amazonSQSClientSupplier = new AmazonSQSClientSupplier() {
        @Override
        public AmazonSQS get() {
            return clientBuilder.build();
        }
    };
}
项目:amazon-sqs-java-messaging-lib    文件:SQSConnectionFactoryTest.java   
@Test
public void canCreateFactoryWithCustomBuilder() throws JMSException {
    AmazonSQSClientBuilder clientBuilder = AmazonSQSClientBuilder.standard().withRegion(Regions.US_EAST_1);
    SQSConnectionFactory factory = new SQSConnectionFactory(new ProviderConfiguration(), clientBuilder);
    SQSConnection connection = factory.createConnection();
    connection.close();
}
项目:amazon-sqs-java-messaging-lib    文件:SQSConnectionFactoryTest.java   
@Test
public void factoryWithCustomBuilderWillCreateNewClient() throws JMSException {
    AmazonSQSClientBuilder clientBuilder = AmazonSQSClientBuilder.standard().withRegion(Regions.US_EAST_1);
    SQSConnectionFactory factory = new SQSConnectionFactory(new ProviderConfiguration(), clientBuilder);
    SQSConnection connection1 = factory.createConnection();
    SQSConnection connection2 = factory.createConnection();

    assertNotSame(connection1.getAmazonSQSClient(), connection2.getAmazonSQSClient()); 

    connection1.close();
    connection2.close();
}
项目:cfnassist    文件:FacadeFactory.java   
private void createAmazonAPIClients() {
       cfnClient = AmazonCloudFormationClientBuilder.defaultClient();
       ec2Client = AmazonEC2ClientBuilder.defaultClient();
       snsClient = AmazonSNSClientBuilder.defaultClient();
       sqsClient = AmazonSQSClientBuilder.defaultClient();
       elbClient = AmazonElasticLoadBalancingClientBuilder.defaultClient();
       s3Client = AmazonS3ClientBuilder.defaultClient();
       rdsClient = AmazonRDSClientBuilder.defaultClient();
       iamClient = AmazonIdentityManagementClientBuilder.defaultClient();
}
项目:wildfly-camel    文件:SQSUtils.java   
public static AmazonSQSClient createSQSClient() {
    BasicCredentialsProvider credentials = BasicCredentialsProvider.standard();
    AmazonSQSClient client = !credentials.isValid() ? null : (AmazonSQSClient)
            AmazonSQSClientBuilder.standard()
            .withCredentials(credentials)
            .withRegion("eu-west-1").build();
    return client;
}
项目:rxjava2-aws    文件:SqsTest.java   
@Test(expected = NullPointerException.class)
public void testBucketNameAndS3FactoryMustBothBeSpecified() {
    Sqs.queueName("queue").sqsFactory(() -> AmazonSQSClientBuilder.defaultClient()).bucketName(null)
            .s3Factory(() -> AmazonS3ClientBuilder.defaultClient()).messages();
}
项目:KafkaToSQS    文件:SQSProducer.java   
public void init(AWSKafkaConfig config){

    this.config = config;
    deDuplicationId  = config.getDeDeupPrefix();

    mXmitDisable = config.getAwsXmitDisable();

    SQSConnectionFactory connectionFactory = new SQSConnectionFactory(
            new ProviderConfiguration(),
            AmazonSQSClientBuilder.standard()
                    .withRegion(config.getRegions())
                    .withCredentials(config.getCredentialsProvider())
            );
    try{ 

        mPreProcessor = config.getPre();
        mXmitReplacement = config.getReplaceXmit(this);
        // Create the connection.
        connection = connectionFactory.createConnection();

        // Create the queue if needed
        //ExampleCommon.ensureQueueExists(connection, config.getQueueName());

        // Create the session
        session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        producer = session.createProducer( session.createQueue( config.getQueueName() ) );

     // Get the wrapped client
        AmazonSQSMessagingClientWrapper client = connection.getWrappedAmazonSQSClient();

        // Create an Amazon SQS queue if it does not already exist
        if (!client.queueExists(config.getQueueName())) {
            Map<String, String> attributes = new HashMap<String, String>();
            attributes.put(config.getQueueName(), "true");
            attributes.put("ContentBasedDeduplication", "true");
            client.createQueue(new CreateQueueRequest().withQueueName(config.getQueueName()).withAttributes(attributes));
        }
    }catch(JMSException e){
    }

}
项目:zipkin-aws    文件:SQSCollector.java   
LazyAmazonSQSClient(Builder builder) {
  this.builder = AmazonSQSClientBuilder.standard()
      .withEndpointConfiguration(builder.endpointConfiguration)
      .withCredentials(builder.credentialsProvider);
}
项目:candlestack    文件:SQSHostMonitorLookup.java   
public SQSHostMonitorLookup( Set<String> contactGroups ) throws CandlestackPropertiesException {

        this.contactGroups = contactGroups;

        queueNamePrefix = GlobalAWSProperties.getSQSQueueNamePrefix();
        queueNameRegex = GlobalAWSProperties.getSQSQueueNameRegex();

        monitorDeadLetter = GlobalAWSProperties.isSQSMonitorDeadLetterEnabled();

        cloudWatchMetrics = GlobalAWSProperties.getSQSCloudwatchMetricsToMonitor();

        queueAttributes = GlobalAWSProperties.getSQSQueueAttributesToMonitor();

        sqsClient = AmazonSQSClientBuilder.standard().withRegion( GlobalAWSProperties.getRegion() ).build();

    }
项目:candlestack    文件:SQSMetricsFetcher.java   
public SQSMetricsFetcher() throws CandlestackException {
    super( SQSUtil.TYPE_NAME, GlobalAWSProperties.getSQSMetricsFetcherSleep() );

    queueNamePrefix = GlobalAWSProperties.getSQSQueueNamePrefix();
    queueNameRegex = GlobalAWSProperties.getSQSQueueNameRegex();

    monitorDeadLetter = GlobalAWSProperties.isSQSMonitorDeadLetterEnabled();

    queueAttributes = GlobalAWSProperties.getSQSQueueAttributesToFetch().stream().map( attribute -> attribute.name() ).collect( Collectors.toList() );

    cloudWatchMetrics = GlobalAWSProperties.getSQSCloudwatchMetricsToFetch();

    sqsClient = AmazonSQSClientBuilder.standard().withRegion( GlobalAWSProperties.getRegion() ).build();

    cloudWatchAccessor = CloudWatchAccessor.getInstance();
}
项目:aws-doc-sdk-examples    文件:LongPolling.java   
public static void main(String[] args)
{
    final String USAGE =
       "To run this example, supply the name of a queue to create and\n" +
       "queue url of an existing queue.\n\n" +
       "Ex: LongPolling <unique-queue-name> <existing-queue-url>\n";

    if (args.length != 2) {
        System.out.println(USAGE);
        System.exit(1);
    }

    String queue_name = args[0];
    String queue_url = args[1];

    final AmazonSQS sqs = AmazonSQSClientBuilder.defaultClient();

    // Enable long polling when creating a queue
    CreateQueueRequest create_request = new CreateQueueRequest()
            .withQueueName(queue_name)
            .addAttributesEntry("ReceiveMessageWaitTimeSeconds", "20");

    try {
        sqs.createQueue(create_request);
    } catch (AmazonSQSException e) {
        if (!e.getErrorCode().equals("QueueAlreadyExists")) {
            throw e;
        }
    }

    // Enable long polling on an existing queue
    SetQueueAttributesRequest set_attrs_request = new SetQueueAttributesRequest()
            .withQueueUrl(queue_url)
            .addAttributesEntry("ReceiveMessageWaitTimeSeconds", "20");
    sqs.setQueueAttributes(set_attrs_request);

    // Enable long polling on a message receipt
    ReceiveMessageRequest receive_request = new ReceiveMessageRequest()
            .withQueueUrl(queue_url)
            .withWaitTimeSeconds(20);
    sqs.receiveMessage(receive_request);
}
项目:paradox-nakadi-consumer    文件:ErrorHandlerConfiguration.java   
@Bean
public AmazonSQS amazonSQS(final SQSConfiguration sqsConfiguration) {
    return AmazonSQSClientBuilder.standard().withRegion(sqsConfiguration.getRegion()).build();
}
项目:amazon-sqs-java-messaging-lib    文件:SQSConnectionFactory.java   
public SQSConnectionFactory(ProviderConfiguration providerConfiguration) {
    this(providerConfiguration, AmazonSQSClientBuilder.standard());
}
项目:cfnassist    文件:EnvironmentSetupForTests.java   
public static AmazonSQS createSQSClient() {
       return AmazonSQSClientBuilder.defaultClient();
}