Skip to content
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

RabbitMQ requeue with additional nack metadata #2239

Merged
merged 2 commits into from
Sep 26, 2023

Conversation

michaelkoetter
Copy link
Contributor

@michaelkoetter michaelkoetter commented Aug 1, 2023

Supports specifying the 'requeue' flag using additional nack metadata. Should fix #2200 .

@michaelkoetter michaelkoetter changed the title RabbitMQ requeue with additional nack metadata #2200 RabbitMQ requeue with additional nack metadata Aug 1, 2023
Copy link
Contributor

@cescoffier cescoffier left a comment

Choose a reason for hiding this comment

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

LGTM

It needs a bit of documentation.
Also, did you try accessing the metadata from the message itself instead of passing it around?

@michaelkoetter
Copy link
Contributor Author

It needs a bit of documentation.

You mean in the markdown docs?

Also, did you try accessing the metadata from the message itself instead of passing it around?

I figured the purpose of nack(Throwable reason, Metadata metadata) was to pass metadata that's relevant for nack'ing the message. From javadoc:

Additional metadata may be provided that the connector can use when nacking the message. The interpretation of metadata is connector-specific.

Sure we could simply add the additional metadata to the message, but then what's the point in having that extra signature for nack 😄

@michaelkoetter
Copy link
Contributor Author

This seems to be tricky. I tried adding the metadata like this

input.addMetadata(new RabbitMQRejectMetadata(true))
                        .nack(new RuntimeException("requeue"));

but then the rejectMessage method doesn't see the metadata. I think this is because an instance of the message is captured in a nack lambda at some earlier point, at least debugging seems to indicate this.

Bildschirmfoto 2023-08-02 um 15 59 30

Still trying to figure it out 😄

Copy link
Collaborator

@ozangunalp ozangunalp left a comment

Choose a reason for hiding this comment

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

Thanks for this! It looks good to me too. It'd be great to add some explanation to the receiving-messages-from-rabbitmq.md#failure-management

On the metadata stuff, we've been kind of entertaining the idea of reworking the message composability and maybe deprecating that method nack(Throwable, Metadata).

The current issue is if the message is intercepted in a way to add metadata etc. nack(Throwable, Metadata) method wasn't really composable, and passed metadata would be completely ignored.

It turns out you've discovered that it is not that easy there are already other problems to achieve this.

@michaelkoetter
Copy link
Contributor Author

@ozangunalp Thanks, I'll add a few sentences to that doc section.

I don't think it's possible to use metadata from the message itself without additional changes. The withMetadata() and addMetadata() methods create a new message instance with references to the original message's ack and nack methods. So in the end, we will always call IncomingRabbitMQMessage.nack() on the original message (which doesn't contain the added metadata)
Also, as metadata is immutable, there is no other way to add metadata to the message.

So should we stick to nack(Throwable, Metadata) or is it a dead end?

@codecov-commenter
Copy link

codecov-commenter commented Aug 3, 2023

Codecov Report

Merging #2239 (be124f3) into main (3bdc102) will decrease coverage by 66.40%.
The diff coverage is 0.00%.

❗ Current head be124f3 differs from pull request most recent head 15702ef. Consider uploading reports for the commit 15702ef to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##               main    #2239       +/-   ##
=============================================
- Coverage     77.95%   11.55%   -66.40%     
+ Complexity     3712      459     -3253     
=============================================
  Files           302      304        +2     
  Lines         12419    12443       +24     
  Branches       1592     1592               
=============================================
- Hits           9681     1438     -8243     
- Misses         2015    10819     +8804     
+ Partials        723      186      -537     
Files Changed Coverage Δ
.../reactive/messaging/rabbitmq/ConnectionHolder.java 0.00% <0.00%> (-76.09%) ⬇️
...ve/messaging/rabbitmq/IncomingRabbitMQMessage.java 0.00% <0.00%> (-73.44%) ⬇️
...reactive/messaging/rabbitmq/RabbitMQConnector.java 0.00% <ø> (-87.17%) ⬇️
...ive/messaging/rabbitmq/RabbitMQRejectMetadata.java 0.00% <0.00%> (ø)
...ctive/messaging/rabbitmq/fault/RabbitMQAccept.java 0.00% <ø> (-100.00%) ⬇️
...ive/messaging/rabbitmq/fault/RabbitMQFailStop.java 0.00% <0.00%> (-100.00%) ⬇️
...ctive/messaging/rabbitmq/fault/RabbitMQReject.java 0.00% <0.00%> (-100.00%) ⬇️
...tive/messaging/rabbitmq/fault/RabbitMQRequeue.java 0.00% <0.00%> (ø)

... and 249 files with indirect coverage changes

@ozangunalp
Copy link
Collaborator

I am working on a prototype to allow this and improve the composability of Messages. I think we'll need to keep nack(Throwable, Metadata) anyways.

@ozangunalp
Copy link
Collaborator

ozangunalp commented Sep 25, 2023

Rebased to main, reviewed the test case, added new failure strategy named requeue and added documentation

@ozangunalp ozangunalp added this to the 4.10.0 milestone Sep 25, 2023
@cescoffier
Copy link
Contributor

It seems that the CI is unhappy.

@ozangunalp ozangunalp self-requested a review September 26, 2023 16:46
@ozangunalp ozangunalp merged commit fee561c into smallrye:main Sep 26, 2023
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RabbitMQ - Missing 'requeue' strategy on rejection/failure of rabbitmq message consumer
4 participants