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

[DefaultLitePullConsumerImpl] There is no way to know whether the consumer has closed. #2152

Closed
JunLu1003 opened this issue Jul 11, 2020 · 2 comments

Comments

@JunLu1003
Copy link

JunLu1003 commented Jul 11, 2020

BUG REPORT

  1. Please describe the issue you observed:
  • What did you do (The steps to reproduce)?

When the project starts, I use DefaultLitePullConsumerImpl as the consumer, and call the consumer's poll(long timeout) method to do some logic.

public class BizConsumer implements CommandLineRunner {

     private DefaultLitePullConsumer consumer;

     @Override
      public void run(String... args) throws Exception {
          consumer = new DefaultLitePullConsumer("group-name");
          consumer.setNamesrvAddr("server address");
          consumer.subscribe(...);
          consumer.start();
          SomeClass.executeAsync(consumer);
      }

      @PreDestroy
      public void destroy {
          if (consumer != null) {
              consumer.shutdown();
          }
      }
}
public class SomeClass {
    @Async
    public void executeAsync(DefaultLitePullConsumer consumer) {
        while (true) {
            /**
             * When Server shutdown, consumer.poll() will throw a Exception
             */
            List<MessageExt> messages = consumer.poll(5 * 1000);
            ....
        }
   }
}

when the project is closed, I call the consumer's shutdown method, but the consumer's poll(long timeout ) is still running, then I got a Exception: java.lang.IllegalStateException: The consumer not running, please start it first.

I try to find a isClosed() or isRunning() method in DefaultLitePullConsumerImpl class, but I cannot find them.

  • What did you expect to see?

Is there a way to know that the consumer client has been closed ?

  • What did you see instead?

java.lang.IllegalStateException: The consumer not running, please start it first.

  1. Please tell us about your environment:

jdk 8
Springboot 2.2.8
rocketmq-spring-boot-starter 2.1.0
CentOS 7

@RongtongJin
Copy link
Contributor

RongtongJin commented Jul 13, 2020

IMO, it is necessary to add such a method. Could you submit a PR to fix it?

@zongtanghu
Copy link
Contributor

Can you submit a PR to fix this issue? @zhangjidi2016

RongtongJin pushed a commit that referenced this issue Sep 17, 2020
jjz921024 pushed a commit to jjz921024/rocketmq that referenced this issue Sep 17, 2020
GenerousMan pushed a commit to GenerousMan/rocketmq that referenced this issue Aug 12, 2022
pulllock pushed a commit to pulllock/rocketmq that referenced this issue Oct 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants