Search in sources :

Example 6 with SqsException

use of software.amazon.awssdk.services.sqs.model.SqsException in project aws-doc-sdk-examples by awsdocs.

the class RemoveQueueTag method removeTag.

// snippet-start:[sqs.java2.remove_tag.main]
public static void removeTag(SqsClient sqsClient, String queueName, String tagName) {
    try {
        GetQueueUrlRequest urlRequest = GetQueueUrlRequest.builder().queueName(queueName).build();
        GetQueueUrlResponse getQueueUrlResponse = sqsClient.getQueueUrl(urlRequest);
        String queueUrl = getQueueUrlResponse.queueUrl();
        UntagQueueRequest untagQueueRequest = UntagQueueRequest.builder().queueUrl(queueUrl).tagKeys(tagName).build();
        sqsClient.untagQueue(untagQueueRequest);
        System.out.println("The " + tagName + " tag was removed from  " + queueName);
    } catch (SqsException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : GetQueueUrlRequest(software.amazon.awssdk.services.sqs.model.GetQueueUrlRequest) SqsException(software.amazon.awssdk.services.sqs.model.SqsException) UntagQueueRequest(software.amazon.awssdk.services.sqs.model.UntagQueueRequest) GetQueueUrlResponse(software.amazon.awssdk.services.sqs.model.GetQueueUrlResponse)

Example 7 with SqsException

use of software.amazon.awssdk.services.sqs.model.SqsException in project aws-doc-sdk-examples by awsdocs.

the class SSEncryptionExample method setEncryption.

// snippet-start:[sqs.java2.sqs_sse_example.main]
public static void setEncryption(SqsClient sqsClient, String queueName, String kmsMasterKeyAlias) {
    try {
        GetQueueUrlRequest urlRequest = GetQueueUrlRequest.builder().queueName(queueName).build();
        GetQueueUrlResponse getQueueUrlResponse = sqsClient.getQueueUrl(urlRequest);
        String queueUrl = getQueueUrlResponse.queueUrl();
        HashMap<QueueAttributeName, String> attributes = new HashMap<>();
        attributes.put(QueueAttributeName.KMS_MASTER_KEY_ID, kmsMasterKeyAlias);
        attributes.put(QueueAttributeName.KMS_DATA_KEY_REUSE_PERIOD_SECONDS, "140");
        SetQueueAttributesRequest attRequest = SetQueueAttributesRequest.builder().queueUrl(queueUrl).attributes(attributes).build();
        sqsClient.setQueueAttributes(attRequest);
        System.out.println("The attributes have been applied to " + queueName);
    } catch (SqsException e) {
        System.err.println(e.awsErrorDetails().errorMessage());
        System.exit(1);
    }
}
Also used : GetQueueUrlRequest(software.amazon.awssdk.services.sqs.model.GetQueueUrlRequest) SqsException(software.amazon.awssdk.services.sqs.model.SqsException) HashMap(java.util.HashMap) GetQueueUrlResponse(software.amazon.awssdk.services.sqs.model.GetQueueUrlResponse) QueueAttributeName(software.amazon.awssdk.services.sqs.model.QueueAttributeName) SetQueueAttributesRequest(software.amazon.awssdk.services.sqs.model.SetQueueAttributesRequest)

Aggregations

SqsException (software.amazon.awssdk.services.sqs.model.SqsException)7 GetQueueUrlRequest (software.amazon.awssdk.services.sqs.model.GetQueueUrlRequest)6 GetQueueUrlResponse (software.amazon.awssdk.services.sqs.model.GetQueueUrlResponse)5 HashMap (java.util.HashMap)2 QueueAttributeName (software.amazon.awssdk.services.sqs.model.QueueAttributeName)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 CreateQueueRequest (software.amazon.awssdk.services.sqs.model.CreateQueueRequest)1 CreateQueueResponse (software.amazon.awssdk.services.sqs.model.CreateQueueResponse)1 DeleteQueueRequest (software.amazon.awssdk.services.sqs.model.DeleteQueueRequest)1 GetQueueAttributesRequest (software.amazon.awssdk.services.sqs.model.GetQueueAttributesRequest)1 GetQueueAttributesResponse (software.amazon.awssdk.services.sqs.model.GetQueueAttributesResponse)1 ListQueueTagsRequest (software.amazon.awssdk.services.sqs.model.ListQueueTagsRequest)1 ListQueueTagsResponse (software.amazon.awssdk.services.sqs.model.ListQueueTagsResponse)1 SendMessageRequest (software.amazon.awssdk.services.sqs.model.SendMessageRequest)1 SetQueueAttributesRequest (software.amazon.awssdk.services.sqs.model.SetQueueAttributesRequest)1 TagQueueRequest (software.amazon.awssdk.services.sqs.model.TagQueueRequest)1 UntagQueueRequest (software.amazon.awssdk.services.sqs.model.UntagQueueRequest)1