alibaba/spring-cloud-alibaba · error · IllegalStateException
defaultMQProducer not initialized
Error message
defaultMQProducer not initialized
What it means
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.
Source
Thrown at spring-cloud-alibaba-starters/spring-cloud-starter-stream-rocketmq/src/main/java/com/alibaba/cloud/stream/binder/rocketmq/integration/outbound/RocketMQProducerMessageHandler.java:117
this.defaultMQProducer = RocketMQProduceFactory
.initRocketMQProducer(destination.getName(), mqProducerProperties);
this.isTrans = defaultMQProducer instanceof TransactionMQProducer;
// Use the default if the partition is on and no customization is available.
this.messageQueueSelector = RocketMQBeanContainerCache.getBean(
mqProducerProperties.getMessageQueueSelector(),
MessageQueueSelector.class,
extendedProducerProperties.isPartitioned()
? new PartitionMessageQueueSelector()
: null);
}
@Override
public void start() {
Instrumentation instrumentation = new Instrumentation(destination.getName(),
this);
try {
if (defaultMQProducer == null) {
throw new IllegalStateException("defaultMQProducer not initialized");
}
defaultMQProducer.start();
// TransactionMQProducer does not currently support custom
// MessageQueueSelector.
if (!isTrans && extendedProducerProperties.isPartitioned()) {
List<MessageQueue> messageQueues = defaultMQProducer
.fetchPublishMessageQueues(destination.getName());
if (extendedProducerProperties.getPartitionCount() != messageQueues
.size()) {
log.info(String.format(
"The partition count of topic '%s' will change from '%s' to '%s'",
destination.getName(),
extendedProducerProperties.getPartitionCount(),
messageQueues.size()));
extendedProducerProperties.setPartitionCount(messageQueues.size());
// may be npe!
if (partitioningInterceptor != null) {
partitioningInterceptor.setPartitionCount(View on GitHub (pinned to 115d590110)
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.
Defensive patterns
Strategy: validation
Validate before calling
// Confirm producer readiness before start.
if (handler.getDefaultMQProducer() == null) {
throw new IllegalStateException("Cannot start: producer not initialized; check prior init errors / group / name-server.");
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- DefaultMQPushConsumer not initialized
- ConfigService is not initialized
- Binding for channel {destination.getName()} has been disable
- DefaultMQPushConsumer init failed, Caused by {e.getMessage()
- pull consumer already running. {this.toString()}
AI-assisted analysis of alibaba/spring-cloud-alibaba@115d590110 (2026-08-14).
Data as JSON: /api/errors/aecbfc64df619282.
Report an issue: GitHub.