Skip to content

[sqs] Support for multi-region client #439

Closed

Description

@Lidbetter

Hi,

I need to support queue interaction from multiple aws regions.

If I were to implement this and contribute back - is that something the project would be interested in?
If so, in broad strokes, do you have a preference for how to do this: changing existing sqs package to support multi region, or a new one specifically for multi region?

Activity

  1. makasim commented on May 9, 2018

    @makasim
    Member

    Hi,

    Sorry, I am not sure I have enough knowledge. Could you please post a link to something regarding the topic or tell more about it?

  2. Lidbetter commented on May 9, 2018

    @Lidbetter
    Author

    This references the S3 client, but the same conventions apply to sqs calls
    https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/s3-multiregion-client.html

    We came to need to use a the multi region client because fifo queues are only available in some regions - when we first needed a fifo queue, there were not available in the same region as the rest of our queues.
    https://aws.amazon.com/sqs/faqs/#service-access-regions

    Example usage:

    $sdk = new Aws\Sdk([
        'Sqs' => [
            'region' => 'us-east-1',
            'version' => '2012-11-05',
            'credentials' => [
                'key' => env('SQS_KEY'),
                'secret' => env('SQS_SECRET'),
            ],
        ],
    ]);
    
    /** @var \Aws\Sqs\SqsClient $sqsClient */
    $sqsClient = $sdk->createSqs();
    // $sqsClient can only make queries to queues in 'us-east-1' region
    
    /** @var \Aws\MultiRegionClient $sqsMultiRegionClient */
    $sqsMultiRegionClient = $sdk->createMultiRegionSqs();
    // $sqsMultiRegionClient needs an '@region' key in each calls input args 
    
    $sqsClient->createQueueAsync([
        'QueueName' => 'email-onboarding.fifo',
        'Attributes' => [
            'FifoQueue' => 'true',
        ],
    ]);
    
    $sqsMultiRegionClient->createQueueAsync([
        '@region' => 'us-east-2',
        'QueueName' => 'email-onboarding.fifo',
        'Attributes' => [
            'FifoQueue' => 'true',
        ],
    ]);
    

    For all the calls the enqueue would need to make, everything is the same + the addition of the region to each sqs api call

    My preference would be for enqueue/sqs to only support the multi region sqs client - since it works fine for single and multi region uses and would provide the most flexibility moving forward.

    I think the only place publicly exposing the client implementation is SqsContext::getClient - but could cause problems for anyone who has extended any of these methods which all internally call SqsContext::getClient:

    SqsContext::getQueueUrl
    SqsContext::declareQueue
    SqsContext::deleteQueue
    SqsContext::purgeQueue
    
    SqsProducer::send
    
    SqsConsumer::acknowledge
    SqsConsumer::reject
    SqsConsumer::receiveMessage
    

    Aws\MultiRegionClient does not publicly expose the method to get individual clients from its pool (1 client per region you attempt to perform an operation on)

  3. makasim commented on Dec 18, 2018

    @makasim
    Member

    supported since 0.9.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions