package com.amazonaws.services.sqs;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeUnit;
import com.amazonaws.services.sqs.util.AbstractAmazonSQSClientWrapper;
import com.amazonaws.services.sqs.util.Constants;
import com.amazonaws.services.sqs.util.SQSQueueUtils;
import software.amazon.awssdk.services.sqs.SqsClient;
import software.amazon.awssdk.services.sqs.model.CreateQueueRequest;
import software.amazon.awssdk.services.sqs.model.CreateQueueResponse;
import software.amazon.awssdk.services.sqs.model.DeleteQueueRequest;
import software.amazon.awssdk.services.sqs.model.QueueAttributeName;
/**
* An AmazonSQS wrapper that only creates virtual, automatically-deleted queues.
*
* This client is built on the functionality of the {@link AmazonSQSIdleQueueDeletingClient}
* and the {@link AmazonSQSVirtualQueuesClient}, and is intended to be a drop-in replacement
* for the AmazonSQS interface in cases where applications need to create many short-lived queues.
*
* It automatically hosts all queues created with the same set of queue attributes on a single
* SQS host queue. Both the host queues and virtual queues will have their "IdleQueueRetentionPeriodSeconds"
* attribute set to 5 minutes.
*/
// TODO-RS: Rename this, as it's not what the AmazonSQSTemporaryQueuesClientBuilder is building!
// The latter supports creating temporary queues, but this class automatically creates ONLY temporary
// queues.
class AmazonSQSTemporaryQueuesClient extends AbstractAmazonSQSClientWrapper {
// We don't necessary support all queue attributes - some will behave differently on a virtual queue
// In particular, a virtual FIFO queue will deduplicate at the scope of its host queue!
private final static Set SUPPORTED_QUEUE_ATTRIBUTES = new HashSet<>(Arrays.asList(
QueueAttributeName.DELAY_SECONDS.toString(),
QueueAttributeName.MAXIMUM_MESSAGE_SIZE.toString(),
QueueAttributeName.MESSAGE_RETENTION_PERIOD.toString(),
QueueAttributeName.POLICY.toString(),
QueueAttributeName.RECEIVE_MESSAGE_WAIT_TIME_SECONDS.toString(),
QueueAttributeName.REDRIVE_POLICY.toString(),
QueueAttributeName.VISIBILITY_TIMEOUT.toString(),
QueueAttributeName.KMS_MASTER_KEY_ID.toString(),
QueueAttributeName.KMS_DATA_KEY_REUSE_PERIOD_SECONDS.toString()));
// These clients are owned by this one, and need to be shutdown when this client is.
private final AmazonSQSIdleQueueDeletingClient deleter;
private final SqsClient virtualizer;
private final ConcurrentMap