-
-
Notifications
You must be signed in to change notification settings - Fork 302
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
Add SnsMessageConverter
and NotificationMessageArgumentResolver
to allow reading SNS messages on SQS
#898
Add SnsMessageConverter
and NotificationMessageArgumentResolver
to allow reading SNS messages on SQS
#898
Conversation
Hi @msosa, thanks for the PR. I'm leaning towards having a separate annotation, since the modules are now separated, and I believe it would make sense for a project to consume an We'd probably want to have a different name for the annotation so that it's not confusing for the users. @MatejNedic, do you have any thoughts on this? Anything I might be missing regarding the integration between the modules? Thanks |
3bfb74d
to
60b1e3d
Compare
60b1e3d
to
3c81c9e
Compare
Makes sense, I have moved all the code into SQS and created a new annotation called |
00ce0a0
to
d61525e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @msosa, thanks, it's looking good.
Added a few comments, let me know if they make sense to you.
It would also be great if you can include an integration test so we can see it in action.
Thanks
.../main/java/io/awspring/cloud/sqs/annotation/AbstractListenerAnnotationBeanPostProcessor.java
Outdated
Show resolved
Hide resolved
...-sqs/src/main/java/io/awspring/cloud/sqs/support/converter/NotificationRequestConverter.java
Outdated
Show resolved
Hide resolved
...-sqs/src/main/java/io/awspring/cloud/sqs/support/converter/NotificationRequestConverter.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am now in the process of making the integration test. I have the test hitting the new code, however its failing due to the message I am providing.
I will fix that and complete the test in another commit later on
...-sqs/src/main/java/io/awspring/cloud/sqs/support/converter/NotificationRequestConverter.java
Outdated
Show resolved
Hide resolved
...-sqs/src/main/java/io/awspring/cloud/sqs/support/converter/NotificationRequestConverter.java
Outdated
Show resolved
Hide resolved
...qs/src/test/java/io/awspring/cloud/sqs/integration/SqsMessageConversionIntegrationTests.java
Show resolved
Hide resolved
Hi, |
Hello @msosa , Do you have plans to further work on this MR? I have implemented something internally very similarly and would love to drop this code in favor of the opensource implementation. The main difference was related to the MessageConverter. In our case we do use CloudEvents and the current MessageConverter is not able to handle well subtypes likes |
HI @gustavomonarin, Yes I do plan on working on this MR, was just waiting for review(I just realized I may not have requested said review) But yeah am open to checking out and change you mentioned and bringing into this MR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good, left a few comments.
.../main/java/io/awspring/cloud/sqs/annotation/AbstractListenerAnnotationBeanPostProcessor.java
Show resolved
Hide resolved
...-sqs/src/main/java/io/awspring/cloud/sqs/support/converter/NotificationRequestConverter.java
Outdated
Show resolved
Hide resolved
/** | ||
* Notification request wrapper. | ||
*/ | ||
public static class NotificationRequest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use a record instead?
@Override | ||
public Object resolveArgument(MethodParameter par, Message<?> msg) throws Exception { | ||
Object object = this.converter.fromMessage(msg, par.getParameterType()); | ||
NotificationRequestConverter.NotificationRequest nr = (NotificationRequestConverter.NotificationRequest) object; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets use Assert.isInstance()
here to throw a pretty message in case the instance doesn't match the expected class?
...qs/src/test/java/io/awspring/cloud/sqs/integration/SqsMessageConversionIntegrationTests.java
Show resolved
Hide resolved
Hey @msosa, really sorry for the delay - I thought I was the one waiting for your reply. Left a few comments on the PR, please let me know if they make sense to you. @gustavomonarin thanks for showing up. Can you share a bit more about what's your proposed change? Thanks. |
…solver` to allow reading SNS messages on SQS
401d7d0
to
1f4c139
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No problem @tomazfernandes, I had it in draft so it was a bit confusing.
Also in regards to @jerchende's comment, I have implemented it locally similar to how it was done previously. But I had to make this method public static. Would it make sense to move NumberParser
to its own class, so we can use the getNumberValue
?
...s/src/main/java/io/awspring/cloud/sqs/annotation/SqsListenerAnnotationBeanPostProcessor.java
Outdated
Show resolved
Hide resolved
@gustavomonarin, can you elaborate on this please? |
In order to easily support generic types, this PR makes the SnsMessageConverter a standard spring SmartMessageConverters. Smart Message Converter is deeply used within spring in a variety of different ways for compatiblity. The current main converter, the CompositeConverter is already a SmartConverter. This change branch contains the minimal and less intrusive changes, especially no touching open public abstract classes.
@gustavomonarin I don't see your PR with these commits, where can I find it? |
@msosa we're pretty much there! The only thing missing is the documentation, let me know if you need any help with that. Thanks! |
It is on the @msosa original repo, as is based on his changes. |
… `ObjectMapper` in `createAdditionalArgumentResolvers`
@tomazfernandes Awesome, appreciate all the feedback! I gave the documentation a try, let me know what you think. |
@gustavomonarin, I looked at your suggestion to switch from implementing the I prefer the solution in this PR as it allows more flexibility for the user and is not a breaking change. Now, not sure how to coordinate this - we do have an eminent version release coming up and it'd be great to have this feature in it. @msosa, how would you feel about incorporating @gustavomonarin's changes into your PR? |
…tification-message Sqs integration with sns notification message
@tomazfernandes of course, I have merged your preferred solution of @gustavomonarin into this PR. Also I have updated the the documentation section to talk about |
NotificationRequestConverter
and NotificationMessageArgumentResolver
to allow reading SNS messages on SQSSnsMessageConverter
and NotificationMessageArgumentResolver
to allow reading SNS messages on SQS
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there @msosa, just one comment on the documentation
Removed the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking great @msosa!
Just a couple of finishing touches.
- Please add
@since 3.1.1
to the javadocs - Please add @gustavomonarin's name under yours in the relevant files
- Please add "Since 3.1.1, when receiving SNS messages..."
That, and we're good to go!
Thanks!
@tomazfernandes Done! I just used @gustavomonarin username as I wasn't sure if exact first/last name. |
Thanks @msosa! @gustavomonarin, please let us know if you want us to name you in any other way. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work @msosa! And thanks @gustavomonarin for the improvement!
Looking forward for more!
Looks great for Single Message processing. What is your recommendation to receive a List of SNSNotificationMessages for batch processing? |
We are also looking for a way to receive a List of SnsNotificationMessages and struggling with this. Any suggestions? |
📢 Type of change
📜 Description
#887
💡 Motivation and Context
It allows for reading an SNS Message on an SQS Queue by using
@NotficationMessage
💚 How did you test it?
Manually(will try to add tests when I have time)
📝 Checklist
🔮 Next steps
@tomazfernandes This is more of a draft for now, this works locally for me but was unsure where these files truly belong. I have put then in the sns project for now, since they use
@NotificationMessage
which lives there, and didn't want SQS project to have a dependency on the SNS one.Let me know if you agree, or we should create a new annotation to be used.
Also in the previous implementation of NotificationRequestConverter it added
MessageAttributes
to the message. For my use-case I was able to remove that completely and things worked fine. Let me know if that is actually needed, but I did seeSqsHeaderMapper
has a lot of the same logic for what was being done forMessageAttributes