8000 [Messenger] Change AmqpExt classes constructor signature by fabpot · Pull Request #28419 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Messenger] Change AmqpExt classes constructor signature #28419

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

Merged
merged 1 commit into from
Sep 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Symfony/Component/Messenger/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ CHANGELOG
4.2.0
-----

* [BC BREAK] The signature of Amqp* classes changed to take a `Connection` as a first argument and an optional
`Serializer` as a second argument.
* [BC BREAK] `SenderLocator` has been renamed to `ContainerSenderLocator`
Be careful as there is still a `SenderLocator` class, but it does not rely on a `ContainerInterface` to find senders.
Instead, it accepts the sender instance itself instead of its identifier in the container.
* [BC BREAK] `MessageSubscriberInterface::getHandledMessages()` return value has changed. The value of an array item
needs to be an associative array or the method name.
needs to be an associative array or the method name.
* `ValidationMiddleware::handle()` and `SendMessageMiddleware::handle()` now require an `Envelope` object
* `EnvelopeItemInterface` doesn't extend `Serializable` anymore
* [BC BREAK] The `ConsumeMessagesCommand` class now takes an instance of `Psr\Container\ContainerInterface`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public function testItSendsAndReceivesMessages()
$connection->setup();
$connection->queue()->purge();

$sender = new AmqpSender($serializer, $connection);
$receiver = new AmqpReceiver($serializer, $connection);
$sender = new AmqpSender($connection, $serializer);
$receiver = new AmqpReceiver($connection, $serializer);

$sender->send($first = Envelope::wrap(new DummyMessage('First')));
$sender->send($second = Envelope::wrap(new DummyMessage('Second')));
Expand All @@ -74,7 +74,7 @@ public function testItReceivesSignals()
$connection->setup();
$connection->queue()->purge();

$sender = new AmqpSender($serializer, $connection);
$sender = new AmqpSender($connection, $serializer);
$sender->send(Envelope::wrap(new DummyMessage('Hello')));

$amqpReadTimeout = 30;
Expand Down Expand Up @@ -123,7 +123,7 @@ public function testItSupportsTimeoutAndTicksNullMessagesToTheHandler()
$connection->setup();
$connection->queue()->purge();

$receiver = new AmqpReceiver($serializer, $connection);
$receiver = new AmqpReceiver($connection, $serializer);

$receivedMessages = 0;
$receiver->receive(function (?Envelope $envelope) use ($receiver, &$receivedMessages) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function testItSendTheDecodedMessageToTheHandlerAndAcknowledgeIt()

$connection->expects($this->once())->method('ack')->with($envelope);

$receiver = new AmqpReceiver($serializer, $connection);
$receiver = new AmqpReceiver($connection, $serializer);
$receiver->receive(function (?Envelope $envelope) use ($receiver) {
$this->assertEquals(new DummyMessage('Hi'), $envelope->getMessage());
$receiver->stop();
Expand All @@ -71,7 +71,7 @@ public function testItNonAcknowledgeTheMessageIfAnExceptionHappened()

$connection->expects($this->once())->method('nack')->with($envelope);

$receiver = new AmqpReceiver($serializer, $connection);
$receiver = new AmqpReceiver($connection, $serializer);
$receiver->receive(function () {
throw new InterruptException('Well...');
});
Expand All @@ -96,7 +96,7 @@ public function testItRejectsTheMessageIfTheExceptionIsARejectMessageExceptionIn
$connection->method('get')->willReturn($envelope);
$connection->expects($this->once())->method('reject')->with($envelope);

$receiver = new AmqpReceiver($serializer, $connection);
$receiver = new AmqpReceiver($connection, $serializer);
$receiver->receive(function () {
throw new WillNeverWorkException('Well...');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function testItSendsTheEncodedMessage()
$connection = $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock();
$connection->expects($this->once())->method('publish')->with($encoded['body'], $encoded['headers']);

$sender = new AmqpSender($serializer, $connection);
$sender = new AmqpSender($connection, $serializer);
$sender->send($envelope);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function testItCreatesTheTransport()
true
);

$expectedTransport = new AmqpTransport($serializer, Connection::fromDsn('amqp://localhost', array('foo' => 'bar'), true));
$expectedTransport = new AmqpTransport(Connection::fromDsn('amqp://localhost', array('foo' => 'bar'), true), $serializer);

$this->assertEquals($expectedTransport, $factory->createTransport('amqp://localhost', array('foo' => 'bar')));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ private function getTransport(SerializerInterface $serializer = null, Connection
$serializer = $serializer ?: $this->getMockBuilder(SerializerInterface::class)->getMock();
$connection = $connection ?: $this->getMockBuilder(Connection::class)->disableOriginalConstructor()->getMock();

return new AmqpTransport($serializer, $connection);
return new AmqpTransport($connection, $serializer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
);

$connection = Connection::fromDsn(getenv('DSN'));
$receiver = new AmqpReceiver($serializer, $connection);
$receiver = new AmqpReceiver($connection, $serializer);

$worker = new Worker($receiver, new class() implements MessageBusInterface {
public function dispatch($envelope)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Symfony\Component\Messenger\Transport\AmqpExt\Exception\RejectMessageExceptionInterface;
use Symfony\Component\Messenger\Transport\ReceiverInterface;
use Symfony\Component\Messenger\Transport\Serialization\Serializer;
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;

/**
Expand All @@ -26,10 +27,10 @@ class AmqpReceiver implements ReceiverInterface
private $connection;
private $shouldStop;

public function __construct(SerializerInterface $serializer, Connection $connection)
public function __construct(Connection $connection, SerializerInterface $serializer = null)
{
$this->serializer = $serializer;
$this->connection = $connection;
$this->serializer = $serializer ?? Serializer::create();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\Transport\SenderInterface;
use Symfony\Component\Messenger\Transport\Serialization\Serializer;
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;

/**
Expand All @@ -25,10 +26,10 @@ class AmqpSender implements SenderInterface
private $serializer;
private $connection;

public function __construct(SerializerInterface $serializer, Connection $connection)
public function __construct(Connection $connection, SerializerInterface $serializer = null)
{
$this->serializer = $serializer;
$this->connection = $connection;
$this->serializer = $serializer ?? Serializer::create();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\Messenger\Transport\AmqpExt;

use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\Transport\Serialization\Serializer;
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
use Symfony\Component\Messenger\Transport\TransportInterface;

Expand All @@ -25,10 +26,10 @@ class AmqpTransport implements TransportInterface
private $receiver;
private $sender;

public function __construct(SerializerInterface $serializer, Connection $connection)
public function __construct(Connection $connection, SerializerInterface $serializer = null)
{
$this->serializer = $serializer;
$this->connection = $connection;
$this->serializer = $serializer ?? Serializer::create();
}

/**
Expand Down Expand Up @@ -57,11 +58,11 @@ public function send(Envelope $envelope): void

private function getReceiver()
{
return $this->receiver = new AmqpReceiver($this->serializer, $this->connection);
return $this->receiver = new AmqpReceiver($this->connection, $this->serializer);
}

private function getSender()
{
return $this->sender = new AmqpSender($this->serializer, $this->connection);
return $this->sender = new AmqpSender($this->connection, $this->serializer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Component\Messenger\Transport\AmqpExt;

use Symfony\Component\Messenger\Transport\Serialization\Serializer;
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
use Symfony\Component\Messenger\Transport\TransportFactoryInterface;
use Symfony\Component\Messenger\Transport\TransportInterface;
Expand All @@ -23,15 +24,15 @@ class AmqpTransportFactory implements TransportFactoryInterface
private $serializer;
private $debug;

public function __construct(SerializerInterface $serializer, bool $debug)
public function __construct(SerializerInterface $serializer = null, bool $debug = false)
{
$this->serializer = $serializer;
$this->serializer = $serializer ?? Serializer::create();
$this->debug = $debug;
}

public function createTransport(string $dsn, array $options): TransportInterface
{
return new AmqpTransport($this->serializer, Connection::fromDsn($dsn, $options, $this->debug));
return new AmqpTransport(Connection::fromDsn($dsn, $options, $this->debug), $this->serializer);
}

public function supports(string $dsn, array $options): bool
Expand Down
0