in src/java/detectors/amazon_sqs_enable_long_polling/AmazonSqsEnableLongPollingCompliant.java [38:82]
public static void createQueues(AmazonSQS sqs,
String queueNamePattern,
int numOfQueues,
String queue_url) {
Map<String, String> attributes = new HashMap<String, String>();
attributes.put("FifoQueue", "true");
attributes.put("ContentBasedDeduplication", "true");
attributes.put("DelaySeconds", "0");
attributes.put("MessageRetentionPeriod", "86400"); // this is 24 shours
attributes.put("ReceiveMessageWaitTimeSeconds", "20"); // enables long polling
for (int i = 1; i < numOfQueues + 1; i++) {
String queueName = queueNamePattern + "-" + i + ".fifo";
// Compliant: enables long polling for efficiency.
CreateQueueRequest createQueueRequest = new CreateQueueRequest(queueName).withAttributes(attributes);
try {
CreateQueueResult res = sqs.createQueue(createQueueRequest);
System.out.println("SQS Queue created, queue url: " + res.getQueueUrl());
} catch (QueueNameExistsException e) {
System.out.println("A queue with name " + queueName
+ " already exist. Renaming it with _v1 suffix before next attempt");
queueName = queueNamePattern + "-" + i + "-v1" + "-src.fifo";
createQueueRequest = new CreateQueueRequest(queueName).withAttributes(attributes);
sqs.createQueue(createQueueRequest);
} catch (QueueDeletedRecentlyException e) {
try {
System.out.println(e.getMessage());
System.out.println("Queue recently deleted. Sleeping for 65 seconds before recreating the queue");
Thread.sleep(65000);
createQueueRequest = new CreateQueueRequest(queueName).withAttributes(attributes);
sqs.createQueue(createQueueRequest);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
ReceiveMessageRequest receive_request = new ReceiveMessageRequest()
.withQueueUrl(queue_url);
sqs.receiveMessage(receive_request);
}
}