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

@SQSListener method: @SnsNotificationMessage parameter doesn't work in batching method signatures #1129

Open
EstelaGarcia opened this issue Apr 3, 2024 · 3 comments
Labels
component: sqs SQS integration related issue status: waiting-for-feedback Waiting for feedback from issuer

Comments

@EstelaGarcia
Copy link

EstelaGarcia commented Apr 3, 2024

Type: Bug

Component:
SQS

Describe the bug
Using Spring Cloud 3.1.1 (have also tried 3.2.0-M1)

The following method signatures result in an SQS Listener that works and converts to the appropriate object:
SQS message, single object

    @SqsListener(value = "queuename")
    public void onMessage(CustomObjectType notification) throws Exception {...}

SQS message, List of objects

    @SqsListener(value = "queuename")
    public void onMessage(List<CustomObjectType> notifications) throws Exception {...}

SNS to SQS message, single object

    @SqsListener(value = "queuename")
    public void onMessage(@SnsNotificationMessage CustomObjectType notification) throws Exception {...}

However the following does not work as no converter can be found:

    @SqsListener(value = "queuename")
    public void onMessage(@SnsNotificationMessage List<CustomObjectType> notification) throws Exception {...}

The error occurs in the following method in io.awspring.cloud.sqs.listener.adapter.AbstractMethodInvokingListenerAdapter

    protected final Object invokeHandler(Collection<Message<T>> messages) {
        try {
            return this.handlerMethod.invoke(MessageBuilder.withPayload(messages).build(), new Object[0]);
        } catch (Exception var3) {
            throw this.createListenerException((Collection)messages, var3);
        }
    }

CustomObjectType is a simple JSON object, and the conversion occurs correctly when handling a single message at a time.

From the comments under the PR that introduced the @SnsNotificationMessage annotation, we are not the only ones experiencing this problem.

@tomazfernandes
Copy link
Contributor

Hi @EstelaGarcia, thanks for opening the issue.

You're right in that batch Sns Messages are not currently supported.

Would you like to contribute a PR with that functionality?

Thanks

@tomazfernandes
Copy link
Contributor

Oh, my mistake, we have a PR already. Please ignore the last message.

Thanks.

@tomazfernandes tomazfernandes added component: sqs SQS integration related issue status: waiting-for-feedback Waiting for feedback from issuer labels Apr 15, 2024
@nandeeshsu
Copy link

Hi,
I'm looking for this feature. Any idea when this will be available?

In the meantime, I copied the NotificationMessageArgumentResolver and the SnsMessageConverter to my code base.
and did the below configuration to use the copied resolve and converter.

`@Configuration
public class AWSSQSConfiguration {

@Bean
SqsListenerConfigurer configurer() {
    return registrar -> registrar.manageMethodArgumentResolvers(
            handlerMethodArgumentResolvers -> handlerMethodArgumentResolvers.add(2,
                    new NotificationMessageArgumentResolver(messageConverter(), new ObjectMapper())));
}

@Bean
public MessageConverter messageConverter() {
    return new MappingJackson2MessageConverter();
}

`

@SqsListener(value = "${com.example.fto.aws.sqs.queue-url}",
            maxMessagesPerPoll="15",
            pollTimeoutSeconds="20",
            messageVisibilitySeconds="5",
            maxConcurrentMessages="15")
public void listenForMultipleMessages(@SnsNotificationMessage List<FTOOrderEventDto> ftoOrderEventDtoList) {

however the conversion still doesn't convert to appropriate object. I'm able to see multiple message read from the SQS and tries to convert into FTOOrderEventDto, however all the properties/attributes are null

Not sure what wrong I'm doing here. any suggestions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: sqs SQS integration related issue status: waiting-for-feedback Waiting for feedback from issuer
Projects
None yet
Development

No branches or pull requests

3 participants