use of software.amazon.awssdk.services.sqs.model.GetQueueUrlRequest in project aws-doc-sdk-examples by awsdocs.
the class AddQueueTags method addTags.
// snippet-start:[sqs.java2.add_tags.main]
public static void addTags(SqsClient sqsClient, String queueName) {
try {
GetQueueUrlRequest urlRequest = GetQueueUrlRequest.builder().queueName(queueName).build();
GetQueueUrlResponse getQueueUrlResponse = sqsClient.getQueueUrl(urlRequest);
String queueUrl = getQueueUrlResponse.queueUrl();
HashMap<String, String> addedTags = new HashMap<>();
addedTags.put("Team", "Development");
addedTags.put("Priority", "Beta");
addedTags.put("Accounting ID", "456def");
TagQueueRequest tagQueueRequest = TagQueueRequest.builder().queueUrl(queueUrl).tags(addedTags).build();
sqsClient.tagQueue(tagQueueRequest);
System.out.println("Tags have been applied to " + queueName);
} catch (SqsException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.sqs.model.GetQueueUrlRequest in project aws-doc-sdk-examples by awsdocs.
the class DeleteQueue method deleteSQSQueue.
// snippet-start:[sqs.java2.sqs_example.delete_queue]
public static void deleteSQSQueue(SqsClient sqsClient, String queueName) {
try {
GetQueueUrlRequest getQueueRequest = GetQueueUrlRequest.builder().queueName(queueName).build();
String queueUrl = sqsClient.getQueueUrl(getQueueRequest).queueUrl();
DeleteQueueRequest deleteQueueRequest = DeleteQueueRequest.builder().queueUrl(queueUrl).build();
sqsClient.deleteQueue(deleteQueueRequest);
} catch (SqsException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.sqs.model.GetQueueUrlRequest in project aws-doc-sdk-examples by awsdocs.
the class SendMessages method sendMessage.
// snippet-start:[sqs.java2.send_recieve_messages.main]
public static void sendMessage(SqsClient sqsClient, String queueName, String message) {
try {
CreateQueueRequest request = CreateQueueRequest.builder().queueName(queueName).build();
CreateQueueResponse createResult = sqsClient.createQueue(request);
GetQueueUrlRequest getQueueRequest = GetQueueUrlRequest.builder().queueName(queueName).build();
String queueUrl = sqsClient.getQueueUrl(getQueueRequest).queueUrl();
SendMessageRequest sendMsgRequest = SendMessageRequest.builder().queueUrl(queueUrl).messageBody(message).delaySeconds(5).build();
sqsClient.sendMessage(sendMsgRequest);
} catch (SqsException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.sqs.model.GetQueueUrlRequest in project aws-doc-sdk-examples by awsdocs.
the class ListQueueTags method listTags.
// snippet-start:[sqs.java2.list_tags.main]
public static void listTags(SqsClient sqsClient, String queueName) {
try {
GetQueueUrlRequest urlRequest = GetQueueUrlRequest.builder().queueName(queueName).build();
GetQueueUrlResponse getQueueUrlResponse = sqsClient.getQueueUrl(urlRequest);
String queueUrl = getQueueUrlResponse.queueUrl();
ListQueueTagsRequest listQueueTagsRequest = ListQueueTagsRequest.builder().queueUrl(queueUrl).build();
ListQueueTagsResponse listQueueTagsResponse = sqsClient.listQueueTags(listQueueTagsRequest);
System.out.println(String.format("ListQueueTags: \tTags for queue %s are %s.\n", queueName, listQueueTagsResponse.tags()));
} catch (SqsException e) {
System.err.println(e.awsErrorDetails().errorMessage());
System.exit(1);
}
}
use of software.amazon.awssdk.services.sqs.model.GetQueueUrlRequest 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);
}
}
Aggregations