software.amazon.awssdk.services.sqs.model.CreateQueueResponse Java Examples

The following examples show how to use software.amazon.awssdk.services.sqs.model.CreateQueueResponse. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SendMessages.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
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 (QueueNameExistsException e) {
            throw e;
        }
    }
 
Example #2
Source File: EmbeddedSqsServer.java    From beam with Apache License 2.0 6 votes vote down vote up
static void start() {
  sqsRestServer = SQSRestServerBuilder.withPort(port).start();

  client =
      SqsClient.builder()
          .credentialsProvider(
              StaticCredentialsProvider.create(AwsBasicCredentials.create("x", "x")))
          .endpointOverride(URI.create(endPoint))
          .region(Region.US_WEST_2)
          .build();

  CreateQueueRequest createQueueRequest =
      CreateQueueRequest.builder().queueName(queueName).build();
  final CreateQueueResponse queue = client.createQueue(createQueueRequest);
  queueUrl = queue.queueUrl();
}
 
Example #3
Source File: SqsQueueManager.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public Queue createQueue(String queueName) {
    CreateQueueResponse queueResp = client.createQueue(q -> q.queueName(queueName));
    GetQueueAttributesResponse queueAttributes = client
            .getQueueAttributes(a -> a.queueUrl(queueResp.queueUrl()).attributeNames(QueueAttributeName.QUEUE_ARN));

    Queue queue = new SqsQueueManager.Queue(queueResp.queueUrl(),
            queueAttributes.attributes().get(QueueAttributeName.QUEUE_ARN));
    queues.put(queueName, queue);
    return queue;
}
 
Example #4
Source File: VisibilityTimeout.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) {
    final String queueName = "testQueue" + new Date().getTime();
    SqsClient sqs = SqsClient.builder().build();

    // First, create a queue (unless it already exists)
    CreateQueueRequest createRequest = CreateQueueRequest.builder()
            .queueName(queueName)
            .build();
    try {
        CreateQueueResponse cqResult = sqs.createQueue(createRequest);
    } catch (QueueNameExistsException e) {
        throw e;
    }

    GetQueueUrlRequest getRequest = GetQueueUrlRequest.builder()
            .queueName(queueName)
            .build();
    final String queue_url = sqs.getQueueUrl(getRequest).queueUrl();

    // Send some messages to the queue
    for (int i = 0; i < 20; i++) {
        SendMessageRequest sendRequest = SendMessageRequest.builder()
                .queueUrl(queueName)
                .messageBody("This is message " + i)
                .build();
        sqs.sendMessage(sendRequest);
    }

    // Change visibility timeout (single)
    changeMessageVisibilitySingle(queueName, 3600);

    // Change visibility timeout (multiple)
    changeMessageVisibilityMultiple(queueName, 2000);
}
 
Example #5
Source File: SqsAsyncStabilityTest.java    From aws-sdk-java-v2 with Apache License 2.0 4 votes vote down vote up
@BeforeAll
public static void setup() {
    queueName = "sqsasyncstabilitytests" + System.currentTimeMillis();
    CreateQueueResponse createQueueResponse = sqsAsyncClient.createQueue(b -> b.queueName(queueName)).join();
    queueUrl = createQueueResponse.queueUrl();
}
 
Example #6
Source File: SendReceiveMessages.java    From aws-doc-sdk-examples with Apache License 2.0 4 votes vote down vote up
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;
        }
    }
 
Example #7
Source File: IntegrationTestBase.java    From aws-sdk-java-v2 with Apache License 2.0 3 votes vote down vote up
/**
 * Helper method to create a SQS queue with a unique name
 *
 * @return The queue url for the created queue
 */
protected String createQueue(SqsAsyncClient sqsClient) {
    CreateQueueResponse res = sqsClient.createQueue(CreateQueueRequest.builder().queueName(getUniqueQueueName()).build()).join();
    return res.queueUrl();
}