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

AWS SQS support more flexible deserialization #2789

Open
kerkhofsd opened this issue Oct 14, 2024 · 0 comments
Open

AWS SQS support more flexible deserialization #2789

kerkhofsd opened this issue Oct 14, 2024 · 0 comments
Labels

Comments

@kerkhofsd
Copy link

version: smallrye-reactive-messaging-aws-sqs:4.24.0

Observed behaviour

Deserialization of SQS body/payload is tightly coupled to the _classname message attribute.
Observations for deserialization to a Message<T> instance:

  • If the _classname attribute is not present, the payload is deserialized as a String. ( Documented )
  • If the _classname attribute is present, default deserialization is possible only to the exact class referenced in the key of this value. Will result in a ClassNotFoundException if it's not available.

Desired behaviour

It would be nice to provide a bit more flexibility here. Ideally, allowing a deserialization for any Class<T> available in the consuming application classpath. (Assuming ofcourse the message body can be deserialized to that specific class.)

Arguments:

  • As far as I can tell the propagation of the _classname SQS attribute is a custom concept, introduced by this library?
  • AS-IS behaviour tightly couples consumers to producers, expecting the use of identical classes / package structure / technology?

Workaround

I'm currently using following workaround:

  1. Include custom SqsReceiveMessageRequestCustomizer to bypass the hardcoded inclusion of _classname header.
@Identifier("my-customizer")
@ApplicationScoped
public class IgnoreClassnameSqsReceiveMessageRequestCustomizer implements SqsReceiveMessageRequestCustomizer {

    @Override
    public void customize(ReceiveMessageRequest.Builder builder) {
        builder.messageAttributeNames(Collections.emptyList());
    }
}

  1. Consume Message<String>
  2. Manual deserialization from String to "type T" using ObjectMapper
@kerkhofsd kerkhofsd changed the title smallrye-sqs: allow more flexible deserialization AWS SQS support more flexible deserialization Oct 14, 2024
@ozangunalp ozangunalp added the sqs label Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants