Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Improvement of message consumption for messenger with AMQP #30454

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

Closed
wants to merge 3 commits into from

Conversation

f2r
Copy link
Contributor

@f2r f2r commented Mar 5, 2019

  • Added Messenger AMQP options consume_fatal and consume_requeue to allow consumer to continue processing other messages without stopping
  • Added Messenger UnrecoverableMessageExceptionInterface and RecoverableMessageExceptionInterface into * AMQP transport into exception to allow handler to nack messages with or without requeue
  • Standardized Messenger AMQP rejection with nack (reject is a nack without multiple rejections abilities which is not used in Messenger context).
Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? yes
Tests pass? yes
Fixed tickets
License MIT
Doc PR

…onsumer to continue processing other messages without stopping

* Added `UnrecoverableMessageExceptionInterface` and `RecoverableMessageExceptionInterface` into AMQP transport into exception to allow handler to nack messages with or without requeue
* Standardized AMQP rejection with `nack` (`reject` is a `nack` without multiple rejections abilities which is not used in Messenger context).
@f2r f2r changed the title * Added AMQP options consume_fatal and consume_requeue to allow c… Improvement of message consumption for messenger with AMQP Mar 6, 2019
@nicolas-grekas nicolas-grekas added this to the next milestone Mar 7, 2019
@f2r f2r mentioned this pull request Mar 14, 2019
36 tasks
throw $e;
if ($connectionCredentials['consume_fatal']) {
throw $e;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm very interested in this part, and these two new options. I'd like to make sure we're thinking about a solution that could be generically applied to other transports and support a "retry" ability. Here's the behavior I'd like to see, which is built off of your ideas:

  1. If RecoverableMessageExceptionInterface is thrown, we re-queue
  2. If UnrecoverableMessageExceptionInterface is thrown, we discard
  3. If there is an AMQPException at any point, probably do nothing - because the message was never ack'ed, so it should still be on the queue? But, it should not kill the worker process (but that's another PR)
  4. If any other Throwable occurs, I think we should requeue always and never throw the exception. However, a few caveats:
  • it should only requeue the message a certain number of times before discarding it (that's the retry stuff)
  • once it hits the retry max, the exception is still not thrown, but perhaps an event is dispatched to handle this.

Morever, I think one of your goals was to standardize a few things (even though we don't have multiple transports yet), which I love! Which is why I'm wondering if we should move some of this logic to the Worker class - #30557 is related. I'm proposing that this method should not handle any exceptions or requeue - it should just handle the message and try to ack it on success. We would move the exception-handling logic into Worker (so we can standardize behavior) and add a few new methods to ReceiverInterface, like requeu() or discard(). Worker would call this under the appropriate situations.

WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, could be a goog idea to move this into the worker ! +1 :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For your point 4, I wanted to keep the compatibility. As you wish :)

@@ -206,6 +206,9 @@ public function channel(): \AMQPChannel
}

$this->amqpChannel = $this->amqpFactory->createChannel($connection);
if (isset($this->connectionCredentials['prefetch_count'])) {
$this->amqpChannel->setPrefetchCount($this->connectionCredentials['prefetch_count']);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an extra feature unrelated to the main purpose of this PR, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's related to AMQP rejection process. By default, RabbitMQ uses a prefetch of 3. If you requeue a message, it comes behind the prefetched messages but not in the queue itself. If consumption speed is not important, you can choose a prefetch of 1, then the messages go back to the queue.

}
} catch (UnrecoverableMessageExceptionInterface $e) {
try {
$this->connection->nack($AMQPEnvelope, AMQP_NOPARAM);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why wouldn't we reject here? 🤔

@sroze
Copy link
Contributor

sroze commented Mar 23, 2019

@f2r the "global retry" pull-request (#30557) has been merged. Can you have a look, update your PR and answer the various comments? Thank you!

@f2r
Copy link
Contributor Author

f2r commented Mar 24, 2019

With global retry and UnrecoverableMessageHandlingException, my PR is no more necessary :)
I'm going to write another PR for prefetching (which is important to me)

@f2r f2r closed this Mar 24, 2019
@f2r f2r deleted the prefetch-and-nack-policy branch March 24, 2019 18:23
@nicolas-grekas nicolas-grekas modified the milestones: next, 4.3 Apr 30, 2019
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.

6 participants