Standard queues are best-effort ordering, which means that messages might be delivered out of order. FIFO queues are guaranteed to preserve message ordering.
xxxxxxxxxx
@Component
public class CreateQueue {
AmazonSQSAsync amazonSQSAsyncClient;
public CreateQueue(AmazonSQSAsync amazonSQSAsyncClient) {
this.amazonSQSAsyncClient = amazonSQSAsyncClient;
}
public void createQueue(String name) {
try {
CreateQueueRequest standardQueueRequest = new CreateQueueRequest()
.withQueueName("SQS_DEMO_QUEUE")
.addAttributesEntry("VisibilityTimeout", "60")
.addAttributesEntry("DelaySeconds", "10")
.addAttributesEntry("MessageRetentionPeriod", "86400");
CreateQueueRequest fifoQueueRequest = new CreateQueueRequest()
.withQueueName("SQS_DEMO_QUEUE.fifo")
.addAttributesEntry("FifoQueue", "true")
.addAttributesEntry("VisibilityTimeout", "60")
.addAttributesEntry("DelaySeconds", "10")
.addAttributesEntry("ContentBasedDeduplication", "true")
.addAttributesEntry("MessageRetentionPeriod", "86400");
CreateQueueResult standardQueueResult = amazonSQSAsyncClient.createQueue(standardQueueRequest);
CreateQueueResult fifoQueueResult = amazonSQSAsyncClient.createQueue(fifoQueueRequest);
} catch (AmazonSQSException exception) {
if (!exception.getErrorCode().equals("QueueAlreadyExists")) {
throw exception;
}
}
}
}