Search in sources :

Example 1 with GetQueueUrlResult

use of com.amazonaws.services.sqs.model.GetQueueUrlResult 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

AmazonClientException (com.amazonaws.AmazonClientException)1 CreateQueueRequest (com.amazonaws.services.sqs.model.CreateQueueRequest)1 CreateQueueResult (com.amazonaws.services.sqs.model.CreateQueueResult)1 GetQueueUrlRequest (com.amazonaws.services.sqs.model.GetQueueUrlRequest)1 GetQueueUrlResult (com.amazonaws.services.sqs.model.GetQueueUrlResult)1 QueueDoesNotExistException (com.amazonaws.services.sqs.model.QueueDoesNotExistException)1