Search in sources :

Example 1 with GetQueueAttributesRequest

use of com.amazonaws.services.sqs.model.GetQueueAttributesRequest in project glacier-cli by carlossg.

the class Glacier method setupSQS.

// ==============
// Helper methods
// ==============
private QueueConfig setupSQS(String sqsQueueName) {
    QueueConfig config = new QueueConfig();
    CreateQueueRequest request = new CreateQueueRequest().withQueueName(sqsQueueName);
    CreateQueueResult result = sqsClient.createQueue(request);
    config.sqsQueueURL = result.getQueueUrl();
    GetQueueAttributesRequest qRequest = new GetQueueAttributesRequest().withQueueUrl(config.sqsQueueURL).withAttributeNames("QueueArn");
    GetQueueAttributesResult qResult = sqsClient.getQueueAttributes(qRequest);
    config.sqsQueueARN = qResult.getAttributes().get("QueueArn");
    Policy sqsPolicy = new Policy().withStatements(new Statement(Effect.Allow).withPrincipals(Principal.AllUsers).withActions(SQSActions.SendMessage).withResources(new Resource(config.sqsQueueARN)));
    Map<String, String> queueAttributes = new HashMap<String, String>();
    queueAttributes.put("Policy", sqsPolicy.toJson());
    sqsClient.setQueueAttributes(new SetQueueAttributesRequest(config.sqsQueueURL, queueAttributes));
    return config;
}
Also used : Policy(com.amazonaws.auth.policy.Policy) GetQueueAttributesResult(com.amazonaws.services.sqs.model.GetQueueAttributesResult) GetQueueAttributesRequest(com.amazonaws.services.sqs.model.GetQueueAttributesRequest) HashMap(java.util.HashMap) Statement(com.amazonaws.auth.policy.Statement) CreateQueueRequest(com.amazonaws.services.sqs.model.CreateQueueRequest) Resource(com.amazonaws.auth.policy.Resource) CreateQueueResult(com.amazonaws.services.sqs.model.CreateQueueResult) SetQueueAttributesRequest(com.amazonaws.services.sqs.model.SetQueueAttributesRequest)

Example 2 with GetQueueAttributesRequest

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

the class DeadLetterQueues method main.

public static void main(String[] args) {
    if (args.length != 2) {
        System.out.println("Usage: DeadLetterQueues <src_queue_name> <dl_queue_name>");
        System.exit(1);
    }
    String src_queue_name = args[0];
    String dl_queue_name = args[1];
    final AmazonSQS sqs = AmazonSQSClientBuilder.defaultClient();
    // Create source queue
    try {
        sqs.createQueue(src_queue_name);
    } catch (AmazonSQSException e) {
        if (!e.getErrorCode().equals("QueueAlreadyExists")) {
            throw e;
        }
    }
    // Create dead-letter queue
    try {
        sqs.createQueue(dl_queue_name);
    } catch (AmazonSQSException e) {
        if (!e.getErrorCode().equals("QueueAlreadyExists")) {
            throw e;
        }
    }
    // Get dead-letter queue ARN
    String dl_queue_url = sqs.getQueueUrl(dl_queue_name).getQueueUrl();
    GetQueueAttributesResult queue_attrs = sqs.getQueueAttributes(new GetQueueAttributesRequest(dl_queue_url).withAttributeNames("QueueArn"));
    String dl_queue_arn = queue_attrs.getAttributes().get("QueueArn");
    // Set dead letter queue with redrive policy on source queue.
    String src_queue_url = sqs.getQueueUrl(src_queue_name).getQueueUrl();
    SetQueueAttributesRequest request = new SetQueueAttributesRequest().withQueueUrl(src_queue_url).addAttributesEntry("RedrivePolicy", "{\"maxReceiveCount\":\"5\", \"deadLetterTargetArn\":\"" + dl_queue_arn + "\"}");
    sqs.setQueueAttributes(request);
}
Also used : GetQueueAttributesResult(com.amazonaws.services.sqs.model.GetQueueAttributesResult) GetQueueAttributesRequest(com.amazonaws.services.sqs.model.GetQueueAttributesRequest) AmazonSQS(com.amazonaws.services.sqs.AmazonSQS) SetQueueAttributesRequest(com.amazonaws.services.sqs.model.SetQueueAttributesRequest) AmazonSQSException(com.amazonaws.services.sqs.model.AmazonSQSException)

Aggregations

GetQueueAttributesRequest (com.amazonaws.services.sqs.model.GetQueueAttributesRequest)2 GetQueueAttributesResult (com.amazonaws.services.sqs.model.GetQueueAttributesResult)2 SetQueueAttributesRequest (com.amazonaws.services.sqs.model.SetQueueAttributesRequest)2 Policy (com.amazonaws.auth.policy.Policy)1 Resource (com.amazonaws.auth.policy.Resource)1 Statement (com.amazonaws.auth.policy.Statement)1 AmazonSQS (com.amazonaws.services.sqs.AmazonSQS)1 AmazonSQSException (com.amazonaws.services.sqs.model.AmazonSQSException)1 CreateQueueRequest (com.amazonaws.services.sqs.model.CreateQueueRequest)1 CreateQueueResult (com.amazonaws.services.sqs.model.CreateQueueResult)1 HashMap (java.util.HashMap)1