Search in sources :

Example 11 with SqsClient

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

the class SSEncryptionExample method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage: " + "   <queueName> <kmsMasterKeyAlias> \n\n" + "Where:\n" + "   queueName - the name of the queue.\n\n" + "   kmsMasterKeyAlias - the alias of the AWS managed CMK for Amazon SQS. ";
    if (args.length != 2) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String queueName = args[0];
    String kmsMasterKeyAlias = args[1];
    SqsClient sqsClient = SqsClient.builder().region(Region.US_WEST_2).build();
    setEncryption(sqsClient, queueName, kmsMasterKeyAlias);
    sqsClient.close();
}
Also used : SqsClient(software.amazon.awssdk.services.sqs.SqsClient)

Example 12 with SqsClient

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

the class VideoDetectSegment method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage: " + "   <bucket> <video> <topicArn> <roleArn>\n\n" + "Where:\n" + "   bucket - the name of the bucket in which the video is located (for example, (for example, myBucket). \n\n" + "   video - the name of video (for example, people.mp4). \n\n" + "   topicArn - the ARN of the Amazon Simple Notification Service (Amazon SNS) topic. \n\n" + "   roleArn - the ARN of the AWS Identity and Access Management (IAM) role to use. \n\n";
    if (args.length != 4) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String bucket = args[0];
    String video = args[1];
    String topicArn = args[2];
    String roleArn = args[3];
    Region region = Region.US_EAST_1;
    RekognitionClient rekClient = RekognitionClient.builder().region(region).build();
    SqsClient sqs = SqsClient.builder().region(Region.US_EAST_1).build();
    NotificationChannel channel = NotificationChannel.builder().snsTopicArn(topicArn).roleArn(roleArn).build();
    StartSegmentDetection(rekClient, channel, bucket, video);
    getSegmentResults(rekClient);
    System.out.println("This example is done!");
    sqs.close();
    rekClient.close();
}
Also used : NotificationChannel(software.amazon.awssdk.services.rekognition.model.NotificationChannel) Region(software.amazon.awssdk.regions.Region) SqsClient(software.amazon.awssdk.services.sqs.SqsClient) RekognitionClient(software.amazon.awssdk.services.rekognition.RekognitionClient)

Example 13 with SqsClient

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

the class SendReceiveMessages method main.

public static void main(String[] args) {
    SqsClient sqsClient = SqsClient.builder().region(Region.US_WEST_2).build();
    try {
        CreateQueueRequest request = CreateQueueRequest.builder().queueName(QUEUE_NAME).build();
        CreateQueueResponse createResult = sqsClient.createQueue(request);
        GetQueueUrlRequest getQueueRequest = GetQueueUrlRequest.builder().queueName(QUEUE_NAME).build();
        String queueUrl = sqsClient.getQueueUrl(getQueueRequest).queueUrl();
        SendMessageRequest sendMsgRequest = SendMessageRequest.builder().queueUrl(queueUrl).messageBody("hello world").delaySeconds(5).build();
        sqsClient.sendMessage(sendMsgRequest);
        // Send multiple messages to the queue
        SendMessageBatchRequest sendBatchRequest = SendMessageBatchRequest.builder().queueUrl(queueUrl).entries(SendMessageBatchRequestEntry.builder().messageBody("Hello from message 1").id("msg_1").build(), SendMessageBatchRequestEntry.builder().messageBody("Hello from message 2").delaySeconds(10).id("msg_2").build()).build();
        sqsClient.sendMessageBatch(sendBatchRequest);
        // Receive messages from the queue
        ReceiveMessageRequest receiveRequest = ReceiveMessageRequest.builder().queueUrl(queueUrl).build();
        List<Message> messages = sqsClient.receiveMessage(receiveRequest).messages();
        // Print out the messages
        for (Message m : messages) {
            System.out.println("\n" + m.body());
        }
    } catch (QueueNameExistsException e) {
        throw e;
    }
}
Also used : CreateQueueResponse(software.amazon.awssdk.services.sqs.model.CreateQueueResponse) GetQueueUrlRequest(software.amazon.awssdk.services.sqs.model.GetQueueUrlRequest) QueueNameExistsException(software.amazon.awssdk.services.sqs.model.QueueNameExistsException) SendMessageBatchRequest(software.amazon.awssdk.services.sqs.model.SendMessageBatchRequest) ReceiveMessageRequest(software.amazon.awssdk.services.sqs.model.ReceiveMessageRequest) Message(software.amazon.awssdk.services.sqs.model.Message) CreateQueueRequest(software.amazon.awssdk.services.sqs.model.CreateQueueRequest) SqsClient(software.amazon.awssdk.services.sqs.SqsClient) SendMessageRequest(software.amazon.awssdk.services.sqs.model.SendMessageRequest)

Example 14 with SqsClient

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

the class DeleteQueue method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage: " + "   <queueName>\n\n" + "Where:\n" + "   queueName - the name of the Amazon SQS queue to delete.\n\n";
    if (args.length != 1) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String queueName = args[0];
    SqsClient sqs = SqsClient.builder().region(Region.US_WEST_2).build();
    deleteSQSQueue(sqs, queueName);
    sqs.close();
}
Also used : SqsClient(software.amazon.awssdk.services.sqs.SqsClient)

Example 15 with SqsClient

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

the class GetQueueAttributes method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage: " + "   <queueName>\n\n" + "Where:\n" + "   queueName - the name of the queue.\n\n";
    if (args.length != 1) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String queueName = args[0];
    SqsClient sqsClient = SqsClient.builder().region(Region.US_WEST_2).build();
    getAttributes(sqsClient, queueName);
    sqsClient.close();
}
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