Search in sources :

Example 6 with CreateQueueResult

use of com.amazonaws.services.sqs.model.CreateQueueResult in project camel by apache.

the class AmazonSQSClientMock method createQueue.

@Override
public CreateQueueResult createQueue(CreateQueueRequest createQueueRequest) throws AmazonServiceException, AmazonClientException {
    String queueName = "https://queue.amazonaws.com/541925086079/" + createQueueRequest.getQueueName();
    queues.put(queueName, createQueueRequest);
    CreateQueueResult result = new CreateQueueResult();
    result.setQueueUrl(queueName);
    return result;
}
Also used : CreateQueueResult(com.amazonaws.services.sqs.model.CreateQueueResult)

Example 7 with CreateQueueResult

use of com.amazonaws.services.sqs.model.CreateQueueResult in project aws-doc-sdk-examples by awsdocs.

the class SendReceiveMessages method main.

public static void main(String[] args) {
    final AmazonSQS sqs = AmazonSQSClientBuilder.defaultClient();
    try {
        CreateQueueResult create_result = sqs.createQueue(QUEUE_NAME);
    } catch (AmazonSQSException e) {
        if (!e.getErrorCode().equals("QueueAlreadyExists")) {
            throw e;
        }
    }
    String queueUrl = sqs.getQueueUrl(QUEUE_NAME).getQueueUrl();
    SendMessageRequest send_msg_request = new SendMessageRequest().withQueueUrl(queueUrl).withMessageBody("hello world").withDelaySeconds(5);
    sqs.sendMessage(send_msg_request);
    // Send multiple messages to the queue
    SendMessageBatchRequest send_batch_request = new SendMessageBatchRequest().withQueueUrl(queueUrl).withEntries(new SendMessageBatchRequestEntry("msg_1", "Hello from message 1"), new SendMessageBatchRequestEntry("msg_2", "Hello from message 2").withDelaySeconds(10));
    sqs.sendMessageBatch(send_batch_request);
    // receive messages from the queue
    List<Message> messages = sqs.receiveMessage(queueUrl).getMessages();
    // delete messages from the queue
    for (Message m : messages) {
        sqs.deleteMessage(queueUrl, m.getReceiptHandle());
    }
}
Also used : SendMessageBatchRequest(com.amazonaws.services.sqs.model.SendMessageBatchRequest) Message(com.amazonaws.services.sqs.model.Message) AmazonSQS(com.amazonaws.services.sqs.AmazonSQS) CreateQueueResult(com.amazonaws.services.sqs.model.CreateQueueResult) SendMessageBatchRequestEntry(com.amazonaws.services.sqs.model.SendMessageBatchRequestEntry) AmazonSQSException(com.amazonaws.services.sqs.model.AmazonSQSException) SendMessageRequest(com.amazonaws.services.sqs.model.SendMessageRequest)

Example 8 with CreateQueueResult

use of com.amazonaws.services.sqs.model.CreateQueueResult in project tutorials by eugenp.

the class SpringCloudSQSIntegrationTest method setupAwsResources.

@BeforeClass
public static void setupAwsResources() {
    sendQueueName = UUID.randomUUID().toString();
    receiveQueueName = SpringCloudSQS.QUEUE_NAME;
    AmazonSQS amazonSQS = SpringCloudAwsTestUtil.amazonSQS();
    CreateQueueResult receiveQueue = amazonSQS.createQueue(receiveQueueName);
    receiveQueueUrl = receiveQueue.getQueueUrl();
    CreateQueueResult sendQueue = amazonSQS.createQueue(sendQueueName);
    sendQueueURl = sendQueue.getQueueUrl();
}
Also used : AmazonSQS(com.amazonaws.services.sqs.AmazonSQS) CreateQueueResult(com.amazonaws.services.sqs.model.CreateQueueResult) BeforeClass(org.junit.BeforeClass)

Example 9 with CreateQueueResult

use of com.amazonaws.services.sqs.model.CreateQueueResult in project java by wavefrontHQ.

the class SQSQueueFactoryImpl method getOrCreateQueue.

private String getOrCreateQueue(String queueName) {
    String queueUrl = queues.getOrDefault(queueName, "");
    if (StringUtils.isNotBlank(queueUrl))
        return queueUrl;
    try {
        GetQueueUrlResult queueUrlResult = client.getQueueUrl(new GetQueueUrlRequest().withQueueName(queueName));
        queueUrl = queueUrlResult.getQueueUrl();
    } catch (QueueDoesNotExistException e) {
        logger.info("Queue " + queueName + " does not exist...creating for first time");
    } catch (AmazonClientException e) {
        logger.log(Level.SEVERE, "Unable to lookup queue by name in aws " + queueName, e);
    }
    try {
        if (StringUtils.isBlank(queueUrl)) {
            CreateQueueRequest request = new CreateQueueRequest();
            request.addAttributesEntry(QueueAttributeName.MessageRetentionPeriod.toString(), "1209600").addAttributesEntry(QueueAttributeName.ReceiveMessageWaitTimeSeconds.toString(), "20").addAttributesEntry(QueueAttributeName.VisibilityTimeout.toString(), "60").setQueueName(queueName);
            CreateQueueResult result = client.createQueue(request);
            queueUrl = result.getQueueUrl();
            queues.put(queueName, queueUrl);
        }
    } catch (AmazonClientException e) {
        logger.log(Level.SEVERE, "Error creating queue in AWS " + queueName, e);
    }
    return queueUrl;
}
Also used : GetQueueUrlRequest(com.amazonaws.services.sqs.model.GetQueueUrlRequest) QueueDoesNotExistException(com.amazonaws.services.sqs.model.QueueDoesNotExistException) AmazonClientException(com.amazonaws.AmazonClientException) CreateQueueRequest(com.amazonaws.services.sqs.model.CreateQueueRequest) CreateQueueResult(com.amazonaws.services.sqs.model.CreateQueueResult) GetQueueUrlResult(com.amazonaws.services.sqs.model.GetQueueUrlResult)

Aggregations

CreateQueueResult (com.amazonaws.services.sqs.model.CreateQueueResult)9 AmazonSQS (com.amazonaws.services.sqs.AmazonSQS)3 CreateQueueRequest (com.amazonaws.services.sqs.model.CreateQueueRequest)3 AmazonSQSException (com.amazonaws.services.sqs.model.AmazonSQSException)2 AmazonClientException (com.amazonaws.AmazonClientException)1 AWSStaticCredentialsProvider (com.amazonaws.auth.AWSStaticCredentialsProvider)1 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)1 Policy (com.amazonaws.auth.policy.Policy)1 Resource (com.amazonaws.auth.policy.Resource)1 Statement (com.amazonaws.auth.policy.Statement)1 AwsClientBuilder (com.amazonaws.client.builder.AwsClientBuilder)1 GetQueueAttributesRequest (com.amazonaws.services.sqs.model.GetQueueAttributesRequest)1 GetQueueAttributesResult (com.amazonaws.services.sqs.model.GetQueueAttributesResult)1 GetQueueUrlRequest (com.amazonaws.services.sqs.model.GetQueueUrlRequest)1 GetQueueUrlResult (com.amazonaws.services.sqs.model.GetQueueUrlResult)1 Message (com.amazonaws.services.sqs.model.Message)1 PurgeQueueRequest (com.amazonaws.services.sqs.model.PurgeQueueRequest)1 QueueDoesNotExistException (com.amazonaws.services.sqs.model.QueueDoesNotExistException)1 SendMessageBatchRequest (com.amazonaws.services.sqs.model.SendMessageBatchRequest)1 SendMessageBatchRequestEntry (com.amazonaws.services.sqs.model.SendMessageBatchRequestEntry)1