You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SqsTemplate ignores the payload class of later receive calls to the same queue #1726
Describe the bug SqsTemplate caches the MessageConversionContext it uses for receive operations per queue, and that context includes the payload class of the first receive call to the queue. Later calls to the same queue convert to the cached class, whatever payload class they pass.
This only shows when the received message has no JavaType header, because the header takes precedence over the context. That is the case the reference docs point to receive(queue, SampleRecord.class) for: messages sent by a producer other than SqsTemplate, or with the type header disabled.
It is the conversionContextCache.computeIfAbsent(endpointName, ...) in SqsTemplate.getReceiveMessageConversionContext. The cache has been there since 3.0.0 and is still on main (4.3.0-SNAPSHOT).
Sample
A queue with a JSON message that has no JavaType header:
SqsOperationstemplate = SqsTemplate.newSyncTemplate(sqsAsyncClient);
template.receive(from -> from.queue("test-queue"));
// payload is the JSON String, as expectedOptional<Message<SampleRecord>> message = template.receive(from -> from.queue("test-queue"), SampleRecord.class);
message.get().getPayload();
// ClassCastException: class java.lang.String cannot be cast to class SampleRecord
I have a fix with a unit test in SqsTemplateTests and can open a PR.
Activity