Search in sources :

Example 1 with ListQueuesRequest

use of com.amazonaws.services.sqs.model.ListQueuesRequest in project aws-doc-sdk-examples by awsdocs.

the class UsingQueues method main.

public static void main(String[] args) {
    AmazonSQS sqs = AmazonSQSClientBuilder.defaultClient();
    // Creating a Queue
    CreateQueueRequest create_request = new CreateQueueRequest(QUEUE_NAME).addAttributesEntry("DelaySeconds", "60").addAttributesEntry("MessageRetentionPeriod", "86400");
    try {
        sqs.createQueue(create_request);
    } catch (AmazonSQSException e) {
        if (!e.getErrorCode().equals("QueueAlreadyExists")) {
            throw e;
        }
    }
    // Get the URL for a queue
    String queue_url = sqs.getQueueUrl(QUEUE_NAME).getQueueUrl();
    // Delete the Queue
    sqs.deleteQueue(queue_url);
    sqs.createQueue("Queue1" + new Date().getTime());
    sqs.createQueue("Queue2" + new Date().getTime());
    sqs.createQueue("MyQueue" + new Date().getTime());
    // List your queues
    ListQueuesResult lq_result = sqs.listQueues();
    System.out.println("Your SQS Queue URLs:");
    for (String url : lq_result.getQueueUrls()) {
        System.out.println(url);
    }
    // List queues with filters
    String name_prefix = "Queue";
    lq_result = sqs.listQueues(new ListQueuesRequest(name_prefix));
    System.out.println("Queue URLs with prefix: " + name_prefix);
    for (String url : lq_result.getQueueUrls()) {
        System.out.println(url);
    }
}
Also used : ListQueuesResult(com.amazonaws.services.sqs.model.ListQueuesResult) CreateQueueRequest(com.amazonaws.services.sqs.model.CreateQueueRequest) AmazonSQS(com.amazonaws.services.sqs.AmazonSQS) Date(java.util.Date) ListQueuesRequest(com.amazonaws.services.sqs.model.ListQueuesRequest) AmazonSQSException(com.amazonaws.services.sqs.model.AmazonSQSException)

Aggregations

AmazonSQS (com.amazonaws.services.sqs.AmazonSQS)1 AmazonSQSException (com.amazonaws.services.sqs.model.AmazonSQSException)1 CreateQueueRequest (com.amazonaws.services.sqs.model.CreateQueueRequest)1 ListQueuesRequest (com.amazonaws.services.sqs.model.ListQueuesRequest)1 ListQueuesResult (com.amazonaws.services.sqs.model.ListQueuesResult)1 Date (java.util.Date)1