Search in sources :

Example 1 with SqsClient

use of software.amazon.awssdk.services.sqs.SqsClient in project beam by apache.

the class SqsUnboundedReaderTest method setupMessages.

private void setupMessages(String... messages) {
    final SqsClient client = testCase.getClient();
    final String queueUrl = testCase.getQueueUrl();
    for (String message : messages) {
        client.sendMessage(b -> b.queueUrl(queueUrl).messageBody(message));
    }
    when(mockSource.getRead().sqsClientProvider()).thenReturn(StaticSqsClientProvider.of(client));
    when(mockSource.getRead().queueUrl()).thenReturn(queueUrl);
}
Also used : SqsClient(software.amazon.awssdk.services.sqs.SqsClient)

Example 2 with SqsClient

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

the class SendReceiveMessages method purgeMyQueue.

public void purgeMyQueue() {
    SqsClient sqsClient = getClient();
    GetQueueUrlRequest getQueueRequest = GetQueueUrlRequest.builder().queueName(QUEUE_NAME).build();
    PurgeQueueRequest queueRequest = PurgeQueueRequest.builder().queueUrl(sqsClient.getQueueUrl(getQueueRequest).queueUrl()).build();
    sqsClient.purgeQueue(queueRequest);
}
Also used : PurgeQueueRequest(software.amazon.awssdk.services.sqs.model.PurgeQueueRequest) SqsClient(software.amazon.awssdk.services.sqs.SqsClient)

Example 3 with SqsClient

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

the class SendReceiveMessages method getMessages.

public String getMessages() {
    List attr = new ArrayList<String>();
    attr.add("Name");
    SqsClient sqsClient = getClient();
    try {
        GetQueueUrlRequest getQueueRequest = GetQueueUrlRequest.builder().queueName(QUEUE_NAME).build();
        String queueUrl = sqsClient.getQueueUrl(getQueueRequest).queueUrl();
        // Receive messages from the queue
        ReceiveMessageRequest receiveRequest = ReceiveMessageRequest.builder().queueUrl(queueUrl).maxNumberOfMessages(10).messageAttributeNames(attr).build();
        List<Message> messages = sqsClient.receiveMessage(receiveRequest).messages();
        com.example.Message myMessage;
        List allMessages = new ArrayList<com.example.Message>();
        // Push the messages to a list
        for (Message m : messages) {
            myMessage = new com.example.Message();
            myMessage.setBody(m.body());
            Map map = m.messageAttributes();
            MessageAttributeValue val = (MessageAttributeValue) map.get("Name");
            myMessage.setName(val.stringValue());
            allMessages.add(myMessage);
        }
        return convertToString(toXml(allMessages));
    } catch (SqsException e) {
        e.getStackTrace();
    }
    return "";
}
Also used : ReceiveMessageRequest(software.amazon.awssdk.services.sqs.model.ReceiveMessageRequest) Message(software.amazon.awssdk.services.sqs.model.Message) SqsClient(software.amazon.awssdk.services.sqs.SqsClient)

Example 4 with SqsClient

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

the class VideoDetect method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage: " + "   <bucket> <video> <queueUrl> <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 the video (for example, people.mp4). \n\n" + "   queueUrl- the URL of a SQS queue. \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 != 5) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String bucket = args[0];
    String video = args[1];
    String queueUrl = args[2];
    String topicArn = args[3];
    String roleArn = args[4];
    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();
    startLabels(rekClient, channel, bucket, video);
    getLabelJob(rekClient, sqs, queueUrl);
    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 5 with SqsClient

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

the class AddQueueTags method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage: " + "   <queueName>\n\n" + "Where:\n" + "   queueName - the name of the queue to which tags are applied.\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();
    addTags(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