{"record":{"id":"53b6f53a33d314ca","repo":"apache/rocketmq","slug":"the-consumer-is-not-in-running-status-servicesta","errorCode":null,"errorMessage":"The consumer is not in running status, {serviceState}","messagePattern":"The consumer is not in running status, (.+?)","errorType":"exception","errorClass":"MQClientException","httpStatus":null,"severity":"error","filePath":"client/src/main/java/org/apache/rocketmq/client/impl/consumer/DefaultMQPullConsumerImpl.java","lineNumber":108,"sourceCode":"    }\n\n    public void registerConsumeMessageHook(final ConsumeMessageHook hook) {\n        this.consumeMessageHookList.add(hook);\n        log.info(\"register consumeMessageHook Hook, {}\", hook.hookName());\n    }\n\n    public void createTopic(String key, String newTopic, int queueNum) throws MQClientException {\n        createTopic(key, newTopic, queueNum, 0);\n    }\n\n    public void createTopic(String key, String newTopic, int queueNum, int topicSysFlag) throws MQClientException {\n        this.isRunning();\n        this.mQClientFactory.getMQAdminImpl().createTopic(key, newTopic, queueNum, topicSysFlag, null);\n    }\n\n    private void isRunning() throws MQClientException {\n        if (this.serviceState != ServiceState.RUNNING) {\n            throw new MQClientException(\"The consumer is not in running status, \"\n                + this.serviceState\n                + FAQUrl.suggestTodo(FAQUrl.CLIENT_SERVICE_NOT_OK),\n                null);\n        }\n    }\n\n    public long fetchConsumeOffset(MessageQueue mq, boolean fromStore) throws MQClientException {\n        this.isRunning();\n        return this.offsetStore.readOffset(mq, fromStore ? ReadOffsetType.READ_FROM_STORE : ReadOffsetType.MEMORY_FIRST_THEN_STORE);\n    }\n\n    public Set<MessageQueue> fetchMessageQueuesInBalance(String topic) throws MQClientException {\n        this.isRunning();\n        if (null == topic) {\n            throw new IllegalArgumentException(\"topic is null\");\n        }\n\n        ConcurrentMap<MessageQueue, ProcessQueue> mqTable = this.rebalanceImpl.getProcessQueueTable();","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/apache/rocketmq/blob/293f5885719fc4aa3619446a1900f58ccfcfdd29/client/src/main/java/org/apache/rocketmq/client/impl/consumer/DefaultMQPullConsumerImpl.java#L90-L126","documentation":"DefaultMQPullConsumerImpl.isRunning() throws MQClientException(\"The consumer is not in running status, ...\") whenever an administrative operation (createTopic, fetchConsumeOffset, fetchMessageQueuesInBalance, pull, etc.) is invoked while serviceState != RUNNING. RocketMQ pull consumers must be start()ed before any of these APIs touch the client factory, offset store, or network.","triggerScenarios":"Calling consumer.fetchConsumeOffset(mq, false) or pull(...) before consumer.start(); calling after shutdown().","commonSituations":"Initialization-order bug (querying offsets in a constructor/@PostConstruct that runs before the start method); using a consumer after calling shutdown() in a cleanup path; failed start() leaving state CREATE_JUST.","solutions":["Ensure consumer.start() completed successfully before any admin/pull call","Guard calls with consumer.isRunning() where the API exposes it, or track started state yourself","Never reuse a consumer instance after shutdown() — create a new one"],"exampleFix":"// before\nDefaultMQPullConsumer c = new DefaultMQPullConsumer(gid);\nlong off = c.fetchConsumeOffset(mq, false);\n\n// after\nDefaultMQPullConsumer c = new DefaultMQPullConsumer(gid);\nc.start();\nlong off = c.fetchConsumeOffset(mq, false);","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    long off = consumer.fetchConsumeOffset(mq, false);\n} catch (MQClientException e) {\n    if (e.getMessage().contains(\"not in running status\")) {\n        // start() not called or shutdown happened — fix lifecycle, do not retry\n    }\n}","preventionTips":["start() the consumer fully before any offset/pull/admin call","Never call APIs on a consumer after shutdown(); create a new instance","Verify start() did not itself fail before proceeding"],"tags":["rocketmq","consumer","lifecycle","illegal-state"],"backgroundTag":null,"analyzedSha":"293f5885719fc4aa3619446a1900f58ccfcfdd29","analyzedAt":"2026-08-14T11:50:13.822Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}