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

Can't inferring the conversion type for RabbitListener be a bit smarter? #1351

Closed
hjohn opened this issue Jun 10, 2021 · 2 comments · Fixed by #1356
Closed

Can't inferring the conversion type for RabbitListener be a bit smarter? #1351

hjohn opened this issue Jun 10, 2021 · 2 comments · Fixed by #1356
Assignees
Milestone

Comments

@hjohn
Copy link

hjohn commented Jun 10, 2021

See #390.

Signatures like this for RabbitListener do not work when there is no type information (no TypeId):

 void listen(MessageProperties props, SomeJavaClass body);
 void listen(MessageProperties props, @Payload SomeJavaClass body);

What is the real limitation here? If a method is annotated with RabbitListener, I'd expect all messages that match its binding to be delivered to the annotated method, and, if this for whatever reason fails due to a bad method signature, a huge exception if not.

However, if the signature goes "bad", the endpoint silently stops working. For example, if you have this:

 void listen(SomeJavaClass body);

And you at some point need the properties (or a header), and you change the signature to this:

 void listen(MessageProperties props, SomeJavaClass body);

...it stops working completely.

What I don't understand is that there is an exception made for Message, so this does work:

 void listen(Message rawMsg, SomeJavaClass body);

Leaving me to have to add this line:

 MessageProperties props = rawMsg.getMessageProperties();  // this can't be done directly...?

Why not also make exceptions for @Header, MessageProperties, etc?

Looking at the code where this is implemented it seems at a maximum a single inferred type can be handled, either 1 header, 1 unannotated parameter that is not Message or a parameter annotated with @Payload.

@garyrussell
Copy link
Contributor

This is because MessageProperties is not available as a first class argument for argument matching only Message, Message<?> and Channel.

All other types (not annotated as @Headers) become candidates for conversion from the incoming payload.

We can certainly add MessageProperties as an available argument for matching, but the current solution (msg.getMessageProperties()) is correct.

@garyrussell garyrussell self-assigned this Jun 10, 2021
@garyrussell garyrussell added this to the 2.4 M1 milestone Jun 10, 2021
@hjohn
Copy link
Author

hjohn commented Jun 10, 2021

Okay, thank you for the quick response. I just banged my head on this why it suddenly stopped working, when all that was different in the message was the missing __TypeId__. I'm glad at least I do not need to configure my own converter in order to make it work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants