{"record":{"id":"aecbfc64df619282","repo":"alibaba/spring-cloud-alibaba","slug":"defaultmqproducer-not-initialized","errorCode":null,"errorMessage":"defaultMQProducer not initialized","messagePattern":"defaultMQProducer not initialized","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"spring-cloud-alibaba-starters/spring-cloud-starter-stream-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/integration/outbound/RocketMQProducerMessageHandler.java","lineNumber":117,"sourceCode":"\t\tthis.defaultMQProducer = RocketMQProduceFactory\n\t\t\t\t.initRocketMQProducer(destination.getName(), mqProducerProperties);\n\t\tthis.isTrans = defaultMQProducer instanceof TransactionMQProducer;\n\t\t// Use the default if the partition is on and no customization is available.\n\t\tthis.messageQueueSelector = RocketMQBeanContainerCache.getBean(\n\t\t\t\tmqProducerProperties.getMessageQueueSelector(),\n\t\t\t\tMessageQueueSelector.class,\n\t\t\t\textendedProducerProperties.isPartitioned()\n\t\t\t\t\t\t? new PartitionMessageQueueSelector()\n\t\t\t\t\t\t: null);\n\t}\n\n\t@Override\n\tpublic void start() {\n\t\tInstrumentation instrumentation = new Instrumentation(destination.getName(),\n\t\t\t\tthis);\n\t\ttry {\n\t\t\tif (defaultMQProducer == null) {\n\t\t\t\tthrow new IllegalStateException(\"defaultMQProducer not initialized\");\n\t\t\t}\n\t\t\tdefaultMQProducer.start();\n\t\t\t// TransactionMQProducer does not currently support custom\n\t\t\t// MessageQueueSelector.\n\t\t\tif (!isTrans && extendedProducerProperties.isPartitioned()) {\n\t\t\t\tList<MessageQueue> messageQueues = defaultMQProducer\n\t\t\t\t\t\t.fetchPublishMessageQueues(destination.getName());\n\t\t\t\tif (extendedProducerProperties.getPartitionCount() != messageQueues\n\t\t\t\t\t\t.size()) {\n\t\t\t\t\tlog.info(String.format(\n\t\t\t\t\t\t\t\"The partition count of topic '%s' will change from '%s' to '%s'\",\n\t\t\t\t\t\t\tdestination.getName(),\n\t\t\t\t\t\t\textendedProducerProperties.getPartitionCount(),\n\t\t\t\t\t\t\tmessageQueues.size()));\n\t\t\t\t\textendedProducerProperties.setPartitionCount(messageQueues.size());\n\t\t\t\t\t// may be npe!\n\t\t\t\t\tif (partitioningInterceptor != null) {\n\t\t\t\t\t\tpartitioningInterceptor.setPartitionCount(","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/alibaba/spring-cloud-alibaba/blob/115d5901102009492e05d5ec18c3f79cad4077d0/spring-cloud-alibaba-starters/spring-cloud-starter-stream-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/integration/outbound/RocketMQProducerMessageHandler.java#L99-L135","documentation":"RocketMQProducerMessageHandler.start throws IllegalStateException('defaultMQProducer not initialized') if the underlying DefaultMQProducer was never constructed before lifecycle start. Like [125] for the consumer, this is an internal-state assertion: you cannot start a producer that failed/skipped initialization.","triggerScenarios":"start() runs while defaultMQProducer is null - producer construction was skipped or failed (e.g. bad name-server config, missing producer group), leaving the field null.","commonSituations":"A producer init exception earlier in the flow that was not propagated; bean lifecycle ordering issue; manual handler creation bypassing RocketMQProduceFactory.initProducer; a partially configured producer.","solutions":["Look for an earlier producer-construction error and fix the root cause (group, name-server).","Ensure RocketMQProduceFactory.initProducer runs and sets defaultMQProducer before start.","Do not manually instantiate the handler; let Spring manage it."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Confirm producer readiness before start.\nif (handler.getDefaultMQProducer() == null) {\n    throw new IllegalStateException(\"Cannot start: producer not initialized; check prior init errors / group / name-server.\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Resolve any producer init failure before relying on the handler.","Always set a producer group and name-server.","Let the binder construct producers via the factory."],"tags":["rocketmq","producer","lifecycle","startup"],"backgroundTag":null,"analyzedSha":"115d5901102009492e05d5ec18c3f79cad4077d0","analyzedAt":"2026-08-14T04:47:13.900Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}