-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Messenger] Add TransportInterface as first class citizen sender+receiver #27164
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Messenger\Transport\AmqpExt; | ||
|
||
use Symfony\Component\Messenger\Transport\Serialization\DecoderInterface; | ||
use Symfony\Component\Messenger\Transport\Serialization\EncoderInterface; | ||
use Symfony\Component\Messenger\Transport\TransportInterface; | ||
|
||
/** | ||
* @author Nicolas Grekas <p@tchwork.com> | ||
*/ | ||
class AmqpTransport implements TransportInterface | ||
{ | ||
private $encoder; | ||
private $decoder; | ||
private $dsn; | ||
private $options; | ||
private $debug; | ||
private $connection; | ||
private $receiver; | ||
private $sender; | ||
|
||
public function __construct(EncoderInterface $encoder, DecoderInterface $decoder, string $dsn, array $options, bool $debug) | ||
{ | ||
$this->encoder = $encoder; | ||
$this->decoder = $decoder; | ||
$this->dsn = $dsn; | ||
$this->options = $options; | ||
$this->debug = $debug; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function receive(callable $handler): void | ||
{ | ||
($this->receiver ?? $this->getReceiver())->receive($hander); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems ternary operator fits better here (same below) ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure what you mean, doesn't feel like to me :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think @yceruto mean next variant: $this->receiver ? $this->receiver->receive($hander) ? $this->getReceiver()->receive($hander) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I meant There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to the manual:
So ternary operator fits better in this case as |
||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function stop(): void | ||
{ | ||
($this->receiver ?? $this->getReceiver())->stop(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function send($message): void | ||
{ | ||
($this->sender ?? $this->getSender())->send($message); | ||
} | ||
|
||
private function getReceiver() | ||
{ | ||
return $this->receiver = new AmqpReceiver($this->decoder, $this->connection ?? $this->getConnection()); | ||
} | ||
|
||
private function getSender() | ||
{ | ||
return $this->sender = new AmqpSender($this->encoder, $this->connection ?? $this->getConnection()); | ||
} | ||
|
||
private function getConnection() | ||
{ | ||
return $this->connection = new Connection($this->dsn, $this->options, $this->debug); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Messenger\Transport; | ||
|
||
/** | ||
* @author Nicolas Grekas <p@tchwork.com> | ||
* | ||
* @experimental in 4.1 | ||
*/ | ||
interface TransportInterface extends ReceiverInterface, SenderInterface | ||
{ | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m not fond of the idea of enforcing
void
as a result. Senders might return something later on, we shouldn’t close that door IMHO.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing void should be ok for the bc policy. See symfony/symfony-docs#9717
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair enough.