in java/client/src/main/java/org/apache/rocketmq/client/java/route/Endpoints.java [85:121]
public Endpoints(String endpoints) {
final String[] addressesStr = endpoints.split(ENDPOINT_SEPARATOR);
this.addresses = new ArrayList<>();
if (addressesStr.length > 1) {
final String firstAddress = addressesStr[0];
String firstHost = firstAddress.substring(0, firstAddress.lastIndexOf(COLON));
this.scheme = IPV4_HOST_PATTERN.matcher(firstHost).matches() ? AddressScheme.IPv4 : AddressScheme.IPv6;
for (String addressStr : addressesStr) {
final int portIndex = addressStr.lastIndexOf(COLON);
String host = addressStr.substring(0, portIndex);
int port = Integer.parseInt(addressStr.substring(1 + portIndex));
final Address addr = new Address(host, port);
addresses.add(addr);
}
this.facade = scheme.getPrefix() + endpoints.replace(ENDPOINT_SEPARATOR, ADDRESS_SEPARATOR);
return;
}
if (endpoints.startsWith(HTTP_PREFIX)) {
endpoints = endpoints.substring(HTTP_PREFIX.length());
}
if (endpoints.startsWith(HTTPS_PREFIX)) {
endpoints = endpoints.substring(HTTPS_PREFIX.length());
}
final int index = endpoints.lastIndexOf(COLON);
int port = index > 0 ? Integer.parseInt(endpoints.substring(1 + index)) : DEFAULT_PORT;
String host = index > 0 ? endpoints.substring(0, index) : endpoints;
if (IPV4_HOST_PATTERN.matcher(host).matches()) {
this.scheme = AddressScheme.IPv4;
} else if (InternetDomainName.isValid(host)) {
this.scheme = AddressScheme.DOMAIN_NAME;
} else {
this.scheme = AddressScheme.IPv6;
}
this.facade = scheme.getPrefix() + host + COLON + port;
final Address address = new Address(host, port);
addresses.add(address);
}