Java Code Examples for com.amazonaws.services.sqs.AmazonSQS#setQueueAttributes()

The following examples show how to use com.amazonaws.services.sqs.AmazonSQS#setQueueAttributes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PubSubUtils.java    From kork with Apache License 2.0 5 votes vote down vote up
public static String ensureQueueExists(
    AmazonSQS amazonSQS, ARN queueARN, ARN topicARN, int sqsMessageRetentionPeriodSeconds) {
  String queueUrl =
      retrySupport.retry(
          () -> getQueueUrl(amazonSQS, queueARN), MAX_RETRIES, RETRY_BACKOFF, EXPONENTIAL);

  HashMap<String, String> attributes = new HashMap<>();
  attributes.put("Policy", buildSQSPolicy(queueARN, topicARN).toJson());
  attributes.put("MessageRetentionPeriod", Integer.toString(sqsMessageRetentionPeriodSeconds));
  amazonSQS.setQueueAttributes(queueUrl, attributes);

  return queueUrl;
}
 
Example 2
Source File: LongPolling.java    From aws-doc-sdk-examples with Apache License 2.0 4 votes vote down vote up
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);
}