Skip to content

[Messenger] Removed deprecated code #41319

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
Jul 11, 2021
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
6 changes: 6 additions & 0 deletions src/Symfony/Component/Messenger/Bridge/Amqp/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
CHANGELOG
=========

6.0
---

* Remove option `prefetch_count`
* Using invalid options will throw a `LogicException`

5.3
---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,39 +125,27 @@ public function testOptionsAreTakenIntoAccountAndOverwrittenByDsn()
);
}

/**
* @group legacy
*/
public function testDeprecationIfInvalidOptionIsPassedWithDsn()
public function testExceptionIfInvalidOptionIsPassedWithDsn()
{
$this->expectDeprecation('Since symfony/messenger 5.1: Invalid option(s) "foo" passed to the AMQP Messenger transport. Passing invalid options is deprecated.');
$this->expectExceptionMessage('Invalid option(s) "foo" passed to the AMQP Messenger transport.');
Connection::fromDsn('amqp://host?foo=bar');
}

/**
* @group legacy
*/
public function testDeprecationIfInvalidOptionIsPassedAsArgument()
public function testExceptionIfInvalidOptionIsPassedAsArgument()
{
$this->expectDeprecation('Since symfony/messenger 5.1: Invalid option(s) "foo" passed to the AMQP Messenger transport. Passing invalid options is deprecated.');
$this->expectExceptionMessage('Invalid option(s) "foo" passed to the AMQP Messenger transport.');
Connection::fromDsn('amqp://host', ['foo' => 'bar']);
}

/**
* @group legacy
*/
public function testDeprecationIfInvalidQueueOptionIsPassed()
public function testExceptionIfInvalidQueueOptionIsPassed()
{
$this->expectDeprecation('Since symfony/messenger 5.1: Invalid queue option(s) "foo" passed to the AMQP Messenger transport. Passing invalid queue options is deprecated.');
$this->expectExceptionMessage('Invalid queue option(s) "foo" passed to the AMQP Messenger transport.');
Connection::fromDsn('amqp://host', ['queues' => ['queueName' => ['foo' => 'bar']]]);
}

/**
* @group legacy
*/
public function testDeprecationIfInvalidExchangeOptionIsPassed()
public function testExceptionIfInvalidExchangeOptionIsPassed()
{
$this->expectDeprecation('Since symfony/messenger 5.1: Invalid exchange option(s) "foo" passed to the AMQP Messenger transport. Passing invalid exchange options is deprecated.');
$this->expectExceptionMessage('Invalid exchange option(s) "foo" passed to the AMQP Messenger transport.');
Connection::fromDsn('amqp://host', ['exchange' => ['foo' => 'bar']]);
}

Expand Down Expand Up @@ -439,28 +427,6 @@ public function testItSetupQueuesOnce()
$connection->publish('body');
}

/**
* @group legacy
*/
public function testSetChannelPrefetchWhenSetup()
{
$factory = new TestAmqpFactory(
$amqpConnection = $this->createMock(\AMQPConnection::class),
$amqpChannel = $this->createMock(\AMQPChannel::class),
$amqpQueue = $this->createMock(\AMQPQueue::class),
$amqpExchange = $this->createMock(\AMQPExchange::class)
);

// makes sure the channel looks connected, so it's not re-created
$amqpChannel->expects($this->any())->method('isConnected')->willReturn(true);

$amqpChannel->expects($this->never())->method('setPrefetchCount');

$this->expectDeprecation('Since symfony/messenger 5.3: The "prefetch_count" option passed to the AMQP Messenger transport has no effect and should not be used.');
$connection = Connection::fromDsn('amqp://localhost?prefetch_count=2', [], $factory);
$connection->setup();
}

public function testAutoSetupWithDelayDeclaresExchangeQueuesAndDelay()
{
$amqpConnection = $this->createMock(\AMQPConnection::class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class Connection
'exchange',
'delay',
'auto_setup',
'prefetch_count',
'retry',
'persistent',
'frame_max',
Expand Down Expand Up @@ -238,11 +237,7 @@ public static function fromDsn(string $dsn, array $options = [], AmqpFactory $am
private static function validateOptions(array $options): void
{
if (0 < \count($invalidOptions = array_diff(array_keys($options), self::AVAILABLE_OPTIONS))) {
trigger_deprecation('symfony/messenger', '5.1', 'Invalid option(s) "%s" passed to the AMQP Messenger transport. Passing invalid options is deprecated.', implode('", "', $invalidOptions));
}

if (isset($options['prefetch_count'])) {
trigger_deprecation('symfony/messenger', '5.3', 'The "prefetch_count" option passed to the AMQP Messenger transport has no effect and should not be used.');
throw new LogicException(sprintf('Invalid option(s) "%s" passed to the AMQP Messenger transport.', implode('", "', $invalidOptions)));
}

if (\is_array($options['queues'] ?? false)) {
Expand All @@ -252,14 +247,14 @@ private static function validateOptions(array $options): void
}

if (0 < \count($invalidQueueOptions = array_diff(array_keys($queue), self::AVAILABLE_QUEUE_OPTIONS))) {
trigger_deprecation('symfony/messenger', '5.1', 'Invalid queue option(s) "%s" passed to the AMQP Messenger transport. Passing invalid queue options is deprecated.', implode('", "', $invalidQueueOptions));
throw new LogicException(sprintf('Invalid queue option(s) "%s" passed to the AMQP Messenger transport.', implode('", "', $invalidQueueOptions)));
}
}
}

if (\is_array($options['exchange'] ?? false)
&& 0 < \count($invalidExchangeOptions = array_diff(array_keys($options['exchange']), self::AVAILABLE_EXCHANGE_OPTIONS))) {
trigger_deprecation('symfony/messenger', '5.1', 'Invalid exchange option(s) "%s" passed to the AMQP Messenger transport. Passing invalid exchange options is deprecated.', implode('", "', $invalidExchangeOptions));
throw new LogicException(sprintf('Invalid exchange option(s) "%s" passed to the AMQP Messenger transport.', implode('", "', $invalidExchangeOptions)));
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/Symfony/Component/Messenger/Bridge/Redis/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
CHANGELOG
=========

6.0
---

* Remove option `tls`
* Using invalid options will throw a `LogicException`

5.3
---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class Connection
'delete_after_reject' => true,
'stream_max_entries' => 0, // any value higher than 0 defines an approximate maximum number of stream entries
'dbindex' => 0,
'tls' => false,
'redeliver_timeout' => 3600, // Timeout before redeliver messages still in pending state (seconds)
'claim_interval' => 60000, // Interval by which pending/abandoned messages should be checked
'lazy' => false,
Expand Down Expand Up @@ -189,11 +188,6 @@ public static function fromDsn(string $dsn, array $redisOptions = [], \Redis|\Re
}

$tls = 'rediss' === $parsedUrl['scheme'];
if (\array_key_exists('tls', $redisOptions)) {
trigger_deprecation('symfony/redis-messenger', '5.3', 'Providing "tls" parameter is deprecated, use "rediss://" DSN scheme instead');
$tls = filter_var($redisOptions['tls'], \FILTER_VALIDATE_BOOLEAN);
unset($redisOptions['tls']);
}

$redeliverTimeout = null;
if (\array_key_exists('redeliver_timeout', $redisOptions)) {
Expand Down Expand Up @@ -272,7 +266,7 @@ private static function validateOptions(array $options): void
$availableOptions[] = 'serializer';

if (0 < \count($invalidOptions = array_diff(array_keys($options), $availableOptions))) {
trigger_deprecation('symfony/messenger', '5.1', 'Invalid option(s) "%s" passed to the Redis Messenger transport. Passing invalid options is deprecated.', implode('", "', $invalidOptions));
throw new LogicException(sprintf('Invalid option(s) "%s" passed to the Redis Messenger transport.', implode('", "', $invalidOptions)));
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/Messenger/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ CHANGELOG
---

* Remove deprecated classes `Symfony/Component/Messenger/Transport/AmqpExt`, `Symfony/Component/Messenger/Transport/Doctrine` and `Symfony/Component/Messenger/Transport/Redis`.
* Class `MessengerPass` cannot be configured with constructor arguments
* Remove constructor arguments and getters for `RedeliveryStamp`'s properties `exceptionMessage` and `flattenException`

5.4
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ protected function displaySingleMessage(Envelope $envelope, SymfonyStyle $io)
$lastRedeliveryStamp = $envelope->last(RedeliveryStamp::class);
/** @var ErrorDetailsStamp|null $lastErrorDetailsStamp */
$lastErrorDetailsStamp = $envelope->last(ErrorDetailsStamp::class);
$lastRedeliveryStampWithException = $this->getLastRedeliveryStampWithException($envelope, true);

$rows = [
['Class', \get_class($envelope->getMessage())],
Expand All @@ -109,12 +108,6 @@ protected function displaySingleMessage(Envelope $envelope, SymfonyStyle $io)
$errorMessage = $lastErrorDetailsStamp->getExceptionMessage();
$errorCode = $lastErrorDetailsStamp->getExceptionCode();
$errorClass = $lastErrorDetailsStamp->getExceptionClass();
} elseif (null !== $lastRedeliveryStampWithException) {
// Try reading the errorMessage for messages that are still in the queue without the new ErrorDetailStamps.
$errorMessage = $lastRedeliveryStampWithException->getExceptionMessage();
if (null !== $lastRedeliveryStampWithException->getFlattenException()) {
$errorClass = $lastRedeliveryStampWithException->getFlattenException()->getClass();
}
}

$rows = array_merge($rows, [
Expand Down Expand Up @@ -144,8 +137,6 @@ protected function displaySingleMessage(Envelope $envelope, SymfonyStyle $io)
$flattenException = null;
if (null !== $lastErrorDetailsStamp) {
$flattenException = $lastErrorDetailsStamp->getFlattenException();
} elseif (null !== $lastRedeliveryStampWithException) {
$flattenException = $lastRedeliveryStampWithException->getFlattenException();
}
$io->writeln(null === $flattenException ? '(no data)' : $dump($flattenException));
} else {
Expand Down Expand Up @@ -177,27 +168,6 @@ protected function getReceiver(string $name = null): ReceiverInterface
return $this->failureTransports->get($name);
}

protected function getLastRedeliveryStampWithException(Envelope $envelope): ?RedeliveryStamp
{
if (null === \func_get_args()[1]) {
trigger_deprecation('symfony/messenger', '5.2', sprintf('Using the "getLastRedeliveryStampWithException" method in the "%s" class is deprecated, use the "Envelope::last(%s)" instead.', self::class, ErrorDetailsStamp::class));
}

// Use ErrorDetailsStamp instead if it is available
if (null !== $envelope->last(ErrorDetailsStamp::class)) {
return null;
}

/** @var RedeliveryStamp $stamp */
foreach (array_reverse($envelope->all(RedeliveryStamp::class)) as $stamp) {
if (null !== $stamp->getExceptionMessage()) {
return $stamp;
}
}

return null;
}

private function createCloner(): ?ClonerInterface
{
if (!class_exists(VarCloner::class)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,10 @@ private function listMessages(?string $failedTransportName, SymfonyStyle $io, in
$lastRedeliveryStamp = $envelope->last(RedeliveryStamp::class);
/** @var ErrorDetailsStamp|null $lastErrorDetailsStamp */
$lastErrorDetailsStamp = $envelope->last(ErrorDetailsStamp::class);
$lastRedeliveryStampWithException = $this->getLastRedeliveryStampWithException($envelope, true);

$errorMessage = '';
if (null !== $lastErrorDetailsStamp) {
$errorMessage = $lastErrorDetailsStamp->getExceptionMessage();
} elseif (null !== $lastRedeliveryStampWithException) {
// Try reading the errorMessage for messages that are still in the queue without the new ErrorDetailStamps.
$errorMessage = $lastRedeliveryStampWithException->getExceptionMessage();
}

$rows[] = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,13 @@
*/
class MessengerPass implements CompilerPassInterface
{
private $handlerTag;
private $busTag;
private $receiverTag;

public function __construct(string $handlerTag = 'messenger.message_handler', string $busTag = 'messenger.bus', string $receiverTag = 'messenger.receiver')
{
if (0 < \func_num_args()) {
trigger_deprecation('symfony/messenger', '5.3', 'Configuring "%s" is deprecated.', __CLASS__);
}

$this->handlerTag = $handlerTag;
$this->busTag = $busTag;
$this->receiverTag = $receiverTag;
}

/**
* {@inheritdoc}
*/
public function process(ContainerBuilder $container)
{
$busIds = [];
foreach ($container->findTaggedServiceIds($this->busTag) as $busId => $tags) {
foreach ($container->findTaggedServiceIds('messenger.bus') as $busId => $tags) {
$busIds[] = $busId;
if ($container->hasParameter($busMiddlewareParameter = $busId.'.middleware')) {
$this->registerBusMiddleware($container, $busId, $container->getParameter($busMiddlewareParameter));
Expand All @@ -76,10 +61,10 @@ private function registerHandlers(ContainerBuilder $container, array $busIds)
$handlersByBusAndMessage = [];
$handlerToOriginalServiceIdMapping = [];

foreach ($container->findTaggedServiceIds($this->handlerTag, true) as $serviceId => $tags) {
foreach ($container->findTaggedServiceIds('messenger.message_handler', true) as $serviceId => $tags) {
foreach ($tags as $tag) {
if (isset($tag['bus']) && !\in_array($tag['bus'], $busIds, true)) {
throw new RuntimeException(sprintf('Invalid handler service "%s": bus "%s" specified on the tag "%s" does not exist (known ones are: "%s").', $serviceId, $tag['bus'], $this->handlerTag, implode('", "', $busIds)));
throw new RuntimeException(sprintf('Invalid handler service "%s": bus "%s" specified on the tag "messenger.message_handler" does not exist (known ones are: "%s").', $serviceId, $tag['bus'], implode('", "', $busIds)));
}

$className = $this->getServiceClass($container, $serviceId);
Expand Down Expand Up @@ -268,7 +253,7 @@ private function registerReceivers(ContainerBuilder $container, array $busIds)
}
}

foreach ($container->findTaggedServiceIds($this->receiverTag) as $id => $tags) {
foreach ($container->findTaggedServiceIds('messenger.receiver') as $id => $tags) {
$receiverClass = $this->getServiceClass($container, $id);
if (!is_subclass_of($receiverClass, ReceiverInterface::class)) {
throw new RuntimeException(sprintf('Invalid receiver "%s": class "%s" must implement interface "%s".', $id, $receiverClass, ReceiverInterface::class));
Expand Down
35 changes: 1 addition & 34 deletions src/Symfony/Component/Messenger/Stamp/RedeliveryStamp.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Symfony\Component\Messenger\Stamp;

use Symfony\Component\ErrorHandler\Exception\FlattenException;
use Symfony\Component\Messenger\Envelope;

/**
Expand All @@ -21,23 +20,11 @@ final class RedeliveryStamp implements StampInterface
{
private $retryCount;
private $redeliveredAt;
private $exceptionMessage;
private $flattenException;

public function __construct(int $retryCount, string $exceptionMessage = null, FlattenException $flattenException = null, \DateTimeInterface $redeliveredAt = null)
public function __construct(int $retryCount, \DateTimeInterface $redeliveredAt = null)
{
$this->retryCount = $retryCount;
$this->redeliveredAt = $redeliveredAt ?? new \DateTimeImmutable();

if (null !== $exceptionMessage) {
trigger_deprecation('symfony/messenger', '5.2', sprintf('Using the "$exceptionMessage" parameter in the "%s" class is deprecated, use the "%s" class instead.', self::class, ErrorDetailsStamp::class));
}
$this->exceptionMessage = $exceptionMessage;

if (null !== $flattenException) {
trigger_deprecation('symfony/messenger', '5.2', sprintf('Using the "$flattenException" parameter in the "%s" class is deprecated, use the "%s" class instead.', self::class, ErrorDetailsStamp::class));
}
$this->flattenException = $flattenException;
}

public static function getRetryCountFromEnvelope(Envelope $envelope): int
Expand All @@ -53,26 +40,6 @@ public function getRetryCount(): int
return $this->retryCount;
}

/**
* @deprecated since Symfony 5.2, use ErrorDetailsStamp instead.
*/
public function getExceptionMessage(): ?string
{
trigger_deprecation('symfony/messenger', '5.2', sprintf('Using the "getExceptionMessage()" method of the "%s" class is deprecated, use the "%s" class instead.', self::class, ErrorDetailsStamp::class));

return $this->exceptionMessage;
}

/**
* @deprecated since Symfony 5.2, use ErrorDetailsStamp instead.
*/
public function getFlattenException(): ?FlattenException
{
trigger_deprecation('symfony/messenger', '5.2', sprintf('Using the "getFlattenException()" method of the "%s" class is deprecated, use the "%s" class instead.', self::class, ErrorDetailsStamp::class));

return $this->flattenException;
}

public function getRedeliveredAt(): \DateTimeInterface
{
return $this->redeliveredAt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function testGetters()

public function testSerialization()
{
$stamp = new RedeliveryStamp(10, null, null, \DateTimeImmutable::createFromFormat(\DateTimeInterface::ISO8601, '2005-08-15T15:52:01+0000'));
$stamp = new RedeliveryStamp(10, \DateTimeImmutable::createFromFormat(\DateTimeInterface::ISO8601, '2005-08-15T15:52:01+0000'));
$this->assertSame('2005-08-15T15:52:01+0000', $stamp->getRedeliveredAt()->format(\DateTimeInterface::ISO8601));
}
}