Is it necessary for the AbstractMessagingMessageConverter
/SqsMessagingMessageConverter
to send the JavaType
header?
#1036
-
Hello 👋 I'll try circle back with a complete example when I've some more time but I'm seeing some odd behaviour with Basically I have a service that...
What I've observed is
I think (but may be wrong) it does this due to the fact Is this necessary? And why do we want to expose our package & class to the SQS consumer? Thanks N.b. This general approach seemed to work fine with
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 9 replies
-
👋 I've raised an issue for this #1037 & also created a sample to replicate the issue (also linked on issue) https://github.com/kevvvvyp/spring-cloud-aws-sample |
Beta Was this translation helpful? Give feedback.
-
Hi @kevvvvyp, thanks for the issue and detailed explanation. You're right in that the framework does deserialization in two places - the first is when the message is received, and the other is when the message gets to the listener method. The reason for this is the listener method is dynamic, so it's not so simple to know beforehand the type the payload should be mapped to. If the first deserialization succeeds, this means you will get a deserialized payload in components such as ErrorHandler and Message Interceptor, otherwise you'll get the JSON and only the proper POJO in the listener method. This is a similar behavior to what happens in e.g. Spring for Apache Kafka. If you're not interested in this, you can configure the Template to not add the type header. Let me know if that works for you. |
Beta Was this translation helpful? Give feedback.
-
Sorry @kevinmcp123, I think I pointed you in the wrong direction. If the goal is to not have the type header and hence skip the first deserialization, you can do this: @Bean
public SqsTemplate sqsTemplate(SqsAsyncClient sqsAsyncClient) {
return SqsTemplate.builder()
.sqsAsyncClient(sqsAsyncClient)
.configureDefaultConverter(converter -> converter.setPayloadTypeHeaderValueFunction(message -> null))
.build();
} This should definitely be better documented - if you'd like to open a PR adding this to the docs it'd be great. Thanks. |
Beta Was this translation helpful? Give feedback.
-
I have the same problem but want to prevent loading the class on the receiving side rather than the sending side. The receiver is a different application from the sender so the class does not exist in the same package. The SqsTemplate solution proposed above did not work for receiving messages. To get around this issue on the receiving side I did the following.
@tomazfernandes Please let me know if there is a better way. (I Tried the SqsTemplate approach and it did not work for receiving messages). |
Beta Was this translation helpful? Give feedback.
Hi @kevvvvyp, thanks for the issue and detailed explanation.
You're right in that the framework does deserialization in two places - the first is when the message is received, and the other is when the message gets to the listener method.
The reason for this is the listener method is dynamic, so it's not so simple to know beforehand the type the payload should be mapped to.
If the first deserialization succeeds, this means you will get a deserialized payload in components such as ErrorHandler and Message Interceptor, otherwise you'll get the JSON and only the proper POJO in the listener method.
This is a similar behavior to what happens in e.g. Spring for Apache Kafka.
If you're not inter…