-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Description
Description
This issue is here in case #38639 is rejected and I have to implement ListableReceiverInterface
in my application code with decoration or inheritance. However, it might be useful in other scenarios as well.
The amazon-sqs-messenger
component instantiates dependencies in dependants, which is a problem for extending the component.
AmazonSqsReceiver
andAmazonSqsSender
are instantiated inAmazonSqsTransport
. -> Please allow passing them via the constructor. Can make the parameters optional and fall back to the default receiver&sender implementations not to force other users to change their calls.- The
Connection::fromDsn
static method contains configuration processing logic that could be used also for other purposes than instantiating aConnection
. For example, someone may want to use an identical instance ofSqsClient
to the one hidden within theConnection
, or even the same instance - so one would create theSqsClient
on their own and pass it to theConnection
's main constructor. -> Please extract a method (or a class) to handle just configuration processing without instantiating any services. See example below.
An extreme solution would be to make all private fields and methods in all classes protected and mark Connection
as not @internal
but I guess what is private and internal is private and internal for a reason so I'm not really asking for that (though it wouldn't hurt me :-)).
I can write the implementation but would like to get an approval of the ticket first.
Example
In a custom implementation of AmazonSqsTransportFactoryInterface::createTransport
:
Before
$transport = new AmazonSqsTransport(Connection::fromDsn($dsn, $options), $serializer);
After (not necessarily exactly that):
[$connectionConfiguration, $clientConfiguration] = ConfigurationFactory::processConfiguration($dsn, $options);
$client = new SqsClient($clientConfiguration);
$connection = new Connection($connectionConfiguration, $client);
$transport = new AmazonSqsTransport(
$connection,
$serializer,
new MyExtendedSqsReceiver($connection, $serializer, $client), // now I can use the client to send some `receiveMessage` requests
new AmazonSqsSender($connection, $serializer)
);
The Connection::fromDsn
method could still exist but be refactored to use ConfigurationFactory::processConfiguration
. This way, the setup shown in the "before" code snippet would still work.