Skip to content

[Bug] RocketMQClientTemplate.receiveAsync closes the shared SimpleConsumer, breaking all subsequent operations #780

Description

@wang-jiahua

Describe the Bug

RocketMQClientTemplate.receiveAsync(...) (rocketmq-v5-client-spring-boot) closes the shared SimpleConsumer right after starting an asynchronous receive:

SimpleConsumer simpleConsumer = this.getSimpleConsumer();
CompletableFuture<List<MessageView>> future = simpleConsumer.receiveAsync(maxMessageNum, invisibleDuration);
simpleConsumer.close();   // closes the shared singleton
return future;

The SimpleConsumer is a template-level singleton whose lifecycle belongs to the Spring bean's destroy() (which already closes it). Closing it here (1) disrupts the in-flight async receive it just started, and (2) permanently breaks the template: every subsequent receive/receiveAsync/ack/changeInvisibleDuration on the same template fails because the consumer is already closed. The synchronous receive() sibling does not close the consumer.

Steps to Reproduce

Call receiveAsync once, then any other consumer operation on the same template — it fails on the closed consumer.

What Did You Expect to See?

receiveAsync behaves like receive(): uses the shared consumer and leaves its lifecycle to destroy().

What Did You See Instead?

The shared consumer is closed after the first receiveAsync, breaking the async path and everything after it.

Additional Context

Fix incoming: remove the simpleConsumer.close() line; destroy() keeps its close. Includes a regression test with a recording fake consumer proving close is no longer invoked and the consumer stays usable.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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