Skip to content

[Messenger] Extract the creation of configuration from Connection::fromDsn to ConfigurationFactory #38989

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

jacekwilczynski
Copy link
Contributor

Q A
Branch? 5.x for features
Bug fix? no
New feature? yes
Deprecations? no
Tickets Fix #38640
License MIT
Doc PR The component doesn't have such low-level documentation.

Problem

I had a case in my app where I wanted to use the same instance of SqsClient in my own code as well as via Connection from this package. While it is possible to inject an SqsClient into Connection::__construct, this makes us miss out on all the useful configuration processing that happens when using Connection::fromDsn, so I had to copy-paste all the code from Connection::fromDsn that's responsible for creating the client configuration.

Solution

By separating the configuration processing logic from the instantiations done in the last line of Connection::fromDsn, we allow users to create an instance of SqsClient on their own without duplicating code.

Usage

Old usage

Backwards compatibility is preserved, i.e. a call to Connection::fromDsn($dsn, $options) will still give you a Connection with a created SqsClient inside it.

New usage

If you want to create an SqsClient yourself, you can do it like this:

[$connectionConfiguration, $clientConfiguration, $queueUrl] = ConfigurationFactory::fromDsn($dsn, $options);
$sqsClient = new SqsClient($clientConfiguration);
$connection = new Connection($connectionConfiguration, $sqsClient, $queueUrl);

@jacekwilczynski jacekwilczynski force-pushed the amazon-sqs-connection-configuration-decoupling branch from 15121b4 to fe3e390 Compare November 4, 2020 17:26
@jderusse jderusse added this to the 5.x milestone Nov 4, 2020
@chalasr
Copy link
Member

chalasr commented Nov 16, 2020

Rebase needed

@fabpot fabpot modified the milestones: 5.4, 6.1 Oct 30, 2021
@fabpot fabpot modified the milestones: 6.1, 6.2 May 20, 2022
@nicolas-grekas nicolas-grekas modified the milestones: 6.2, 6.3 Nov 5, 2022
@magikid
Copy link
Contributor

magikid commented Nov 27, 2022

@jacekwilczynski Would you mind rebasing this please?

@nicolas-grekas nicolas-grekas modified the milestones: 6.3, 6.4 May 23, 2023
@nicolas-grekas nicolas-grekas modified the milestones: 6.4, 7.1 Nov 15, 2023
@xabbuh
Copy link
Member

xabbuh commented Nov 27, 2023

closing here as the PR seems to be stalled

@xabbuh xabbuh closed this Nov 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use DI & SRP to make Amazon SQS Messenger more extensible
9 participants