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;
}
Aggregations