Skip to content

MessagingConverter's in SqsMessageListenerContainerFactory's is ignored #1546

@mayleaf

Description

@mayleaf

Type: Bug

Component: SQS

Description

I've identified an issue with message converter handling in AbstractListenerAnnotationBeanPostProcessor that prevents custom message converters from being applied to @SqsListener methods.

Environment

  • io.awspring.cloud:spring-cloud-aws-sqs:3.4.2
  • io.awspring.cloud:spring-cloud-aws-sns:3.4.2
  • Spring Boot 2.7.18

Problem

The issue occurs in the initialization flow of the AbstractListenerAnnotationBeanPostProcessor:

  1. The configureDefaultHandlerMethodFactory(DefaultMessageHandlerMethodFactory handlerMethodFactory) method receives a DefaultMessageHandlerMethodFactory instance
  2. Its methodArgumentResolvers is initialized with a converter created by createCompositeMessageConverter()
  3. While SqsMessageListenerContainerFactory allows registering custom message converters, these converters are overridden by the composite converter created in step 2

Expected Behavior

Custom message converters registered in SqsMessageListenerContainerFactory should be used to resolve method arguments in @SqsListener annotated handlers, enabling proper deserialization of complex types (e.g., LocalDateTime with JavaTimeModule).

Actual Behavior

The custom message converters are overridden by createCompositeMessageConverter(), causing deserialization failures for messages that require custom converters.

Code Sample

@SqsListener("${aws.sqs.queue-name}")
public void handle(@Payload CustomEventType event, Acknowledgement acknowledgment) {
    // Handler logic
}
@ToString
@Getter
class CustomEventType {
    private LocalDateTime createdAt;
    private String publisherId;
    private List<OtherCustomType> elems;
}

Steps to Reproduce

  1. Register a custom message converter (e.g., with JavaTimeModule) in SqsMessageListenerContainerFactory
  2. Create an @SqsListener method with a @Payload parameter containing LocalDateTime fields
  3. Send a message to the queue
  4. Observe deserialization failure despite the custom converter being registered

Impact

This prevents using custom serialization/deserialization logic with @SqsListener methods, requiring workarounds or manual message parsing.

Possible Solution

The createCompositeMessageConverter() method could be modified to include or respect custom converters registered in the container factory, rather than overriding them.

Would appreciate any guidance on the intended design or if this should be addressed in a future release. Happy to provide additional details or submit a PR if helpful.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions