use of software.amazon.awssdk.services.sqs.SqsClient in project aws-doc-sdk-examples by awsdocs.
the class SQSExample method main.
public static void main(String[] args) {
String queueName = "queue" + System.currentTimeMillis();
SqsClient sqsClient = SqsClient.builder().region(Region.US_WEST_2).build();
// Perform various tasks on the Amazon SQS queue
String queueUrl = createQueue(sqsClient, queueName);
listQueues(sqsClient);
listQueuesFilter(sqsClient, queueUrl);
List<Message> messages = receiveMessages(sqsClient, queueUrl);
sendBatchMessages(sqsClient, queueUrl);
changeMessages(sqsClient, queueUrl, messages);
deleteMessages(sqsClient, queueUrl, messages);
sqsClient.close();
}
use of software.amazon.awssdk.services.sqs.SqsClient in project aws-doc-sdk-examples by awsdocs.
the class SendMessages method main.
public static void main(String[] args) {
final String USAGE = "\n" + "Usage: " + " <queueName> <message>\n\n" + "Where:\n" + " queueName - the name of the queue.\n\n" + " message - the message to send.\n\n";
if (args.length != 2) {
System.out.println(USAGE);
System.exit(1);
}
String queueName = args[0];
String message = args[1];
SqsClient sqsClient = SqsClient.builder().region(Region.US_WEST_2).build();
sendMessage(sqsClient, queueName, message);
sqsClient.close();
}
use of software.amazon.awssdk.services.sqs.SqsClient in project aws-doc-sdk-examples by awsdocs.
the class SendReceiveMessages method processMessage.
public void processMessage(com.example.Message msg) {
SqsClient sqsClient = SqsClient.builder().region(Region.US_WEST_2).build();
try {
// Get user
MessageAttributeValue attributeValue = MessageAttributeValue.builder().stringValue(msg.getName()).dataType("String").build();
Map myMap = new HashMap<String, MessageAttributeValue>();
myMap.put("Name", attributeValue);
GetQueueUrlRequest getQueueRequest = GetQueueUrlRequest.builder().queueName(QUEUE_NAME).build();
String queueUrl = sqsClient.getQueueUrl(getQueueRequest).queueUrl();
// generate the work item ID
UUID uuid = UUID.randomUUID();
String msgId1 = uuid.toString();
SendMessageRequest sendMsgRequest = SendMessageRequest.builder().queueUrl(queueUrl).messageAttributes(myMap).messageGroupId("GroupA").messageDeduplicationId(msgId1).messageBody(msg.getBody()).build();
sqsClient.sendMessage(sendMsgRequest);
} catch (SqsException e) {
e.getStackTrace();
}
}
Aggregations