apache/dubbo · error · IllegalStateException
Consumer is not initialized
Error message
Consumer is not initialized
What it means
Thrown by ReferenceConfigBase.getMetaData when the config has been refreshed but its ConsumerConfig is still null. The consumer should be resolved during preProcessRefresh(); if it is absent after refresh, the reference is in an inconsistent state. This usually points to missing consumer configuration or a broken refresh lifecycle.
Source
Thrown at dubbo-common/src/main/java/org/apache/dubbo/config/ReferenceConfigBase.java:167
List<String> prefixes = new ArrayList<>();
// dubbo.reference.{interface-name}
prefixes.add(DUBBO + ".reference." + interfaceName);
return prefixes;
}
@Override
@Transient
public Map<String, String> getMetaData() {
return getMetaData(null);
}
@Override
public Map<String, String> getMetaData(String prefix) {
Map<String, String> metaData = new HashMap<>();
ConsumerConfig consumer = this.getConsumer();
// consumer should be initialized at preProcessRefresh()
if (isRefreshed() && consumer == null) {
throw new IllegalStateException("Consumer is not initialized");
}
// use consumer attributes as default value
appendAttributes(metaData, consumer, prefix);
appendAttributes(metaData, this, prefix);
return metaData;
}
/**
* Get service interface class of this reference.
* The actual service type of remote provider.
*
* @return
*/
public Class<?> getServiceInterfaceClass() {
Class<?> actualInterface = interfaceClass;
if (interfaceClass == GenericService.class) {
try {
if (getInterfaceClassLoader() != null) {View on GitHub (pinned to 3a3043227f)
Solutions
- Ensure a ConsumerConfig is registered (explicitly or via dubbo.consumer.* properties) and reachable from the reference's module scope.
- Verify the consumerIds on the ReferenceConfigBase point to an existing ConsumerConfig.
- Re-trigger the full config refresh lifecycle rather than partial refresh so preProcessRefresh() runs.
Example fix
// before
referenceConfig.setConsumer(null); // or consumerIds points to missing config
// after
ConsumerConfig consumer = new ConsumerConfig();
consumer.setId("myConsumer");
configManager.addConsumer(consumer);
referenceConfig.setConsumer(consumer); Defensive patterns
Strategy: validation
Validate before calling
// Before calling getMetaData, ensure consumer is wired (if refreshed)
if (referenceConfig.isRefreshed() && referenceConfig.getConsumer() == null) {
// re-resolve consumer via consumerIds or default before proceeding
ConsumerConfig c = moduleConfigManager
.getConsumer(referenceConfig.getConsumerIds())
.orElseThrow(() -> new IllegalStateException("ConsumerConfig missing"));
referenceConfig.setConsumer(c);
} Try / catch
try {
Map<String, String> meta = referenceConfig.getMetaData();
} catch (IllegalStateException e) {
if (e.getMessage().contains("Consumer is not initialized")) {
// re-run the refresh lifecycle or wire the consumer explicitly
}
throw e;
} Prevention
- Always register a ConsumerConfig (or dubbo.consumer.* defaults) before refreshing references.
- Ensure consumerIds reference existing ConsumerConfig entries.
- Use the standard refresh lifecycle rather than ad-hoc refresh calls.
When it happens
Trigger: Calling getMetaData() on a ReferenceConfigBase that has isRefreshed() == true but getConsumer() == null. The consumer is normally set during preProcessRefresh() by looking up ConsumerConfig by consumerIds or default.
Common situations: Referencing a consumer id that does not exist (so it was never resolved). Refreshing the config outside the normal lifecycle that populates the consumer. Removing or renaming the ConsumerConfig after the reference was refreshed. Module/Application scope changes that orphan the consumer lookup.
Related errors
- Directory of type {simpleName} already destroyed for service
- Rpc cluster invoker for {getInterface()} on consumer {NetUti
- 6
- register bean failed! name=${name}, type=${className}
- ScopeBeanFactory is destroyed
AI-assisted analysis of apache/dubbo@3a3043227f (2026-08-14).
Data as JSON: /api/errors/3b575cd6dce787ca.
Report an issue: GitHub.