apache/rocketmq · critical · MQClientException
NO_NAME_SERVER_EXCEPTION
NO_NAME_SERVER_EXCEPTION
Error message
No name server address, please set it.{} What it means
MQClientException with responseCode ClientErrorCode.NO_NAME_SERVER_EXCEPTION, thrown by validateNameServerSetting() when the client's remoting layer has an empty/null name server address list. It fires at send time (end of sendDefaultImpl / invokeMessageQueueSelector, after route lookup already failed) to give a clearer reason than 'no route': without a name server, no routes can ever be resolved. Response code lets programmatic handlers distinguish config errors from missing topics.
Source
Thrown at client/src/main/java/org/apache/rocketmq/client/impl/producer/DefaultMQProducerImpl.java:732
}
validateNameServerSetting();
throw new MQClientException("No route info for this topic, " + msg.getTopic(), null);
}
public MessageQueue selectOneMessageQueue(final TopicPublishInfo tpInfo, final String lastBrokerName, final boolean resetIndex) {
return this.mqFaultStrategy.selectOneMessageQueue(tpInfo, lastBrokerName, resetIndex);
}
public void updateFaultItem(final String brokerName, final long currentLatency, boolean isolation,
boolean reachable) {
this.mqFaultStrategy.updateFaultItem(brokerName, currentLatency, isolation, reachable);
}
private void validateNameServerSetting() throws MQClientException {
List<String> nsList = this.getMqClientFactory().getMQClientAPIImpl().getNameServerAddressList();
if (null == nsList || nsList.isEmpty()) {
throw new MQClientException(
"No name server address, please set it." + FAQUrl.suggestTodo(FAQUrl.NAME_SERVER_ADDR_NOT_EXIST_URL), null).setResponseCode(ClientErrorCode.NO_NAME_SERVER_EXCEPTION);
}
}
private SendResult sendDefaultImpl(
Message msg,
final CommunicationMode communicationMode,
final SendCallback sendCallback,
final long timeout
) throws MQClientException, RemotingException, MQBrokerException, InterruptedException {
this.makeSureStateOK();
Validators.checkMessage(msg, this.defaultMQProducer);
final long invokeID = random.nextLong();
long beginTimestampFirst = System.currentTimeMillis();
long beginTimestampPrev = beginTimestampFirst;
long endTimestamp = beginTimestampFirst;
TopicPublishInfo topicPublishInfo = this.tryToFindTopicPublishInfo(msg.getTopic());View on GitHub (pinned to 293f588571)
Solutions
- Set the name server explicitly on the client: producer.setNamesrvAddr("10.0.0.1:9876;10.0.0.2:9876") before start()
- Or set the system property -Drocketmq.namesrv.addr=... / env NAMESRV_ADDR before the producer is constructed (property is read at client build time)
- If using the 5.x gRPC client, set the nameserver for route discovery separately (namesrvAddr on ClientConfiguration) in addition to the gRPC endpoint
- Verify at startup: log producer.getClientConfig() name server list and fail fast in your bootstrap if empty
Example fix
// before
DefaultMQProducer p = new DefaultMQProducer("g"); p.start(); p.send(msg); // no ns addr
// after
DefaultMQProducer p = new DefaultMQProducer("g");
p.setNamesrvAddr(System.getenv("NAMESRV_ADDR")); // e.g. 10.0.0.1:9876
p.start();
p.send(msg); Defensive patterns
Strategy: validation
Validate before calling
String ns = System.getProperty("rocketmq.namesrv.addr", System.getenv("NAMESRV_ADDR"));
if (Strings.isNullOrEmpty(ns)) {
throw new ConfigurationException("Set rocketmq.namesrv.addr or NAMESRV_ADDR before starting the producer");
}
DefaultMQProducer p = new DefaultMQProducer(group);
p.setNamesrvAddr(ns); Try / catch
try {
producer.send(msg);
} catch (MQClientException e) {
if (e.getResponseCode() == ClientErrorCode.NO_NAME_SERVER_EXCEPTION) {
throw new ConfigurationException("RocketMQ name server address missing", e);
}
throw e;
} Prevention
- Always call setNamesrvAddr explicitly instead of relying on ambient properties
- Add a startup assertion that the client's name server list is non-empty
- Inject nameserver config via environment and validate it in the health endpoint
- Distinguish NO_NAME_SERVER_EXCEPTION by response code in central error handling
When it happens
Trigger: triggerScenarios
Common situations: commonSituations
Related errors
- The configuration item NamesrvAddr is not configured
- The authenticationMetadataProvider is not configured
- The authenticationMetadataProvider is not configured.
- The authorizationMetadataProvider is not configured.
- NetAddress examine scope Exception netAddress is %s
AI-assisted analysis of apache/rocketmq@293f588571 (2026-08-14).
Data as JSON: /api/errors/f70ce675f874303c.
Report an issue: GitHub.