Skip to content

Kotlin Suspend functions should be asyncReplies=true in HandlerAdapter, so that the acknowledge is MANUAL #3161

@jensbaitingerbosch

Description

@jensbaitingerbosch

When you have a @RabbitListener that returns a Mono or CompletableFuture, that is automatically recognized the the HandlerAdapter, an the ListenerContainer sets the AcknowledgeMode to MANUAL automatically.

It would be great if the same behaviour is true for Kotlin suspend methods.

Current Behavior

When you start the Application, there is a warning:
[rabbit-simple-251] WARN o.s.a.r.l.a.MessagingMessageListenerAdapter - Container AcknowledgeMode must be MANUAL for a Mono<?> return type(or Kotlin suspend function); otherwise the container will ack the message immediately

And messages cannot be NACKed.

Context

Workaround: set the config property spring.rabbitmq.listener.simple.acknowledge-mode to manual (or spring.rabbitmq.listener.direct.acknowledge-mode, dependend on what you are using.

Code that checks for async result:

public HandlerAdapter(InvocableHandlerMethod invokerHandlerMethod) {
this.invokerHandlerMethod = invokerHandlerMethod;
this.delegatingHandler = null;
this.asyncReplies = (AbstractAdaptableMessageListener.monoPresent
&& MonoHandler.isMono(invokerHandlerMethod.getMethod().getReturnType()))
|| CompletableFuture.class.isAssignableFrom(invokerHandlerMethod.getMethod().getReturnType());
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions