Search in sources :

Example 16 with SqsClient

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();
}
Also used : SqsClient(software.amazon.awssdk.services.sqs.SqsClient)

Example 17 with SqsClient

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();
}
Also used : SqsClient(software.amazon.awssdk.services.sqs.SqsClient)

Example 18 with SqsClient

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();
    }
}
Also used : SqsClient(software.amazon.awssdk.services.sqs.SqsClient)

Aggregations

SqsClient (software.amazon.awssdk.services.sqs.SqsClient)18 Region (software.amazon.awssdk.regions.Region)2 RekognitionClient (software.amazon.awssdk.services.rekognition.RekognitionClient)2 NotificationChannel (software.amazon.awssdk.services.rekognition.model.NotificationChannel)2 Message (software.amazon.awssdk.services.sqs.model.Message)2 ReceiveMessageRequest (software.amazon.awssdk.services.sqs.model.ReceiveMessageRequest)2 Date (java.util.Date)1 CreateQueueRequest (software.amazon.awssdk.services.sqs.model.CreateQueueRequest)1 CreateQueueResponse (software.amazon.awssdk.services.sqs.model.CreateQueueResponse)1 GetQueueUrlRequest (software.amazon.awssdk.services.sqs.model.GetQueueUrlRequest)1 PurgeQueueRequest (software.amazon.awssdk.services.sqs.model.PurgeQueueRequest)1 QueueNameExistsException (software.amazon.awssdk.services.sqs.model.QueueNameExistsException)1 SendMessageBatchRequest (software.amazon.awssdk.services.sqs.model.SendMessageBatchRequest)1 SendMessageRequest (software.amazon.awssdk.services.sqs.model.SendMessageRequest)1