Java Code Examples for com.amazonaws.services.sqs.model.CreateQueueRequest#getQueueName()

The following examples show how to use com.amazonaws.services.sqs.model.CreateQueueRequest#getQueueName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AmazonSQSIdleQueueDeletingClient.java    From amazon-sqs-java-temporary-queues-client with Apache License 2.0 5 votes vote down vote up
@Override
public CreateQueueResult createQueue(CreateQueueRequest request) {
    Map<String, String> attributes = new HashMap<>(request.getAttributes());
    Optional<Long> retentionPeriod = getRetentionPeriod(attributes);
    if (!retentionPeriod.isPresent()) {
        return super.createQueue(request);
    }

    String queueName = request.getQueueName();
    if (!queueName.startsWith(queueNamePrefix)) {
        throw new IllegalArgumentException();
    }

    CreateQueueRequest superRequest = request.clone()
            .withQueueName(queueName)
            .withAttributes(attributes);

    CreateQueueResult result = super.createQueue(superRequest);
    String queueUrl = result.getQueueUrl();

    String retentionPeriodString = retentionPeriod.get().toString();
    amazonSqsToBeExtended.tagQueue(queueUrl,
            Collections.singletonMap(IDLE_QUEUE_RETENTION_PERIOD_TAG, retentionPeriodString));

    // TODO-RS: Filter more carefully to all attributes valid for createQueue 
    List<String> attributeNames = Arrays.asList(QueueAttributeName.ReceiveMessageWaitTimeSeconds.toString(),
                                                QueueAttributeName.VisibilityTimeout.toString());
    Map<String, String> createdAttributes = amazonSqsToBeExtended.getQueueAttributes(queueUrl, attributeNames).getAttributes();
    createdAttributes.put(IDLE_QUEUE_RETENTION_PERIOD, retentionPeriodString);

    QueueMetadata metadata = new QueueMetadata(queueName, queueUrl, createdAttributes);
    queues.put(queueUrl, metadata);

    metadata.heartbeater = executor.scheduleAtFixedRate(() -> heartbeatToQueue(queueUrl), 
            0, heartbeatIntervalSeconds, TimeUnit.SECONDS);

    return result;
}
 
Example 2
Source File: AmazonSQSVirtualQueuesClient.java    From amazon-sqs-java-temporary-queues-client with Apache License 2.0 5 votes vote down vote up
@Override
public CreateQueueResult createQueue(CreateQueueRequest request) {
    String hostQueueUrl = request.getAttributes().get(VIRTUAL_QUEUE_HOST_QUEUE_ATTRIBUTE);
    if (hostQueueUrl == null) {
        return amazonSqsToBeExtended.createQueue(request);
    }

    Map<String, String> attributes = new HashMap<>(request.getAttributes());
    attributes.remove(VIRTUAL_QUEUE_HOST_QUEUE_ATTRIBUTE);

    Optional<Long> retentionPeriod = AmazonSQSIdleQueueDeletingClient.getRetentionPeriod(attributes);

    if (!attributes.isEmpty()) {
        throw new IllegalArgumentException("Virtual queues do not support setting these queue attributes independently of their host queues: "
                + attributes.keySet());
    }

    HostQueue host = hostQueues.computeIfAbsent(hostQueueUrl, HostQueue::new);
    VirtualQueue virtualQueue = new VirtualQueue(host, request.getQueueName(), retentionPeriod);

    // There is clearly a race condition here between checking the size and
    // adding to the map, but that's fine since this is just a loose upper bound
    // and it avoids synchronizing all calls on something like an AtomicInteger.
    // The worse case scenario is that the map has X entries more than the maximum
    // where X is the number of threads concurrently creating queues.
    if (virtualQueues.size() > MAXIMUM_VIRTUAL_QUEUES_COUNT) {
        throw new IllegalStateException("Cannot create virtual queue: the number of virtual queues would exceed the maximum of "
                + MAXIMUM_VIRTUAL_QUEUES_COUNT);
    }
    virtualQueues.put(virtualQueue.getID().getVirtualQueueName(), virtualQueue);

    if (LOG.isDebugEnabled()) {
        LOG.debug(String.format("Total Virtual Queue Created is %s and Queue Name is %s", virtualQueues.size(), virtualQueue.getID().getVirtualQueueName()));
    }

    return new CreateQueueResult().withQueueUrl(virtualQueue.getID().getQueueUrl());
}
 
Example 3
Source File: MockSQS.java    From amazon-sqs-java-temporary-queues-client with Apache License 2.0 5 votes vote down vote up
@Override
public CreateQueueResult createQueue(CreateQueueRequest request) {
    String queueName = request.getQueueName();
    String queueUrl = accountPrefix + queueName;
    queues.put(queueName, new MockSQSQueue(queueName));
    return new CreateQueueResult().withQueueUrl(queueUrl);
}