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

  1. Look for an earlier producer-construction error and fix the root cause (group, name-server).
  2. Ensure RocketMQProduceFactory.initProducer runs and sets defaultMQProducer before start.
  3. 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

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


AI-assisted analysis of alibaba/spring-cloud-alibaba@115d590110 (2026-08-14). Data as JSON: /api/errors/aecbfc64df619282. Report an issue: GitHub.