php-enqueue / enqueue-dev

Message Queue, Job Queue, Broadcasting, WebSockets packages for PHP, Symfony, Laravel, Magento. DEVELOPMENT REPOSITORY - provided by Forma-Pro
https://enqueue.forma-pro.com/
MIT License
2.17k stars 429 forks source link

Add tagQueue and untagQueue to Amazon SQS client #1305

Closed wodor closed 10 months ago

wodor commented 1 year ago

AWS sdk contains tagQueue and untagQueue methods that were not exposed via this client. This is the only way to tag a queue, as tagging on creation does not work in AWS php sdk.

I am aware that using it requires some work - writing custom SqsContext and changing declareQueue like this

    public function declareQueue(SqsDestination $dest): void
    {
        $sqsClient = $this->decoratedContext->getSqsClient();
        $sqsClient = $this->decoratedContext->getSqsClient();

        $result = $sqsClient->createQueue(
            [
                '@region' => $dest->getRegion(),
                'Attributes' => $dest->getAttributes(),
                'QueueName' => $dest->getQueueName(),
            ]
        );

        if (!$result->hasKey('QueueUrl')) {
            throw new \RuntimeException(sprintf('Cannot create queue. queueName: "%s"', $dest->getQueueName()));
        }

        $sqsClient->tagQueue(
            [
                '@region' => $dest->getRegion(),
                'QueueUrl' => $result->get('QueueUrl'),
                'Tags' => [
                    'Product' => 'myProduc',
                    'ServiceName' => 'workers',
                    'Environment' => 'qa'
                ],
            ]
        );

        $this->queueUrls[$dest->getQueueName()] = $result->get('QueueUrl');
}

If the Authors of enqueue are interested in it I can PR a change to SqsDestination that would allow setting tags and using them in this updated method.

makasim commented 1 year ago

if I understand it correctly you can already do what you want:

<?php

$sqsClient->getAWSClient()->tagQueue([
    '@region' => $dest->getRegion(),
    'QueueUrl' => $result->get('QueueUrl'),
    'Tags' => [
        'Product' => 'myProduc',
        'ServiceName' => 'workers',
        'Environment' => 'qa'
    ],
]);