In Dubbo, when a Provider starts, it does two main things: it starts the server and registers the service with the registry. When starting the server, it needs to bind the socket, and when registering the service with the registry, it also needs to send the socket’s unique identifier as the service address.
host
when host
is not set in dubbo
?host
in dubbo
, can we use a hostname or domain instead of an IP address as host
?The general dubbo protocol configuration is as follows:
...
<dubbo:protocol name="dubbo" port="20890" />
...
It can be seen that only the port number is configured, and the host is not set. So what is the host set in this case?
Looking at the code, it is found that in org.apache.dubbo.config.ServiceConfig#findConfigedHosts()
, the default host is obtained through InetAddress.getLocalHost().getHostAddress()
. Its return values are as follows:
In addition, the host
can be configured through the dubbo.protocol
or dubbo.provider
host
attribute, supporting both IP addresses and domain names, as follows:
...
<dubbo:protocol name="dubbo" port="20890" host="www.example.com"/>
...
See Setting host in Dubbo via environment variables
Some deployment scenarios require dynamically specifying the service registration address, such as specifying the IP of the host machine under the Docker bridge network mode to achieve external communication. Dubbo provides two pairs of system properties at startup for setting the communication IP and port address.
All four configuration items are optional, if not configured, dubbo will automatically obtain the IP and port, please flexibly choose configurations based on specific deployment scenarios. Dubbo supports multiple protocols; if an application exposes multiple different protocol services and requires separate IP or port for each service, please add the protocol prefix to these properties. For example:
PORT_TO_REGISTRY or IP_TO_REGISTRY will not be used as the default PORT_TO_BIND or IP_TO_BIND, but the opposite is valid. For example:
PORT_TO_REGISTRY=20881
and IP_TO_REGISTRY=30.5.97.6
will not affect PORT_TO_BIND
and IP_TO_BIND
PORT_TO_BIND=20881
and IP_TO_BIND=30.5.97.6
will default PORT_TO_REGISTRY=20881
and IP_TO_REGISTRY=30.5.97.6
host
can be configured through the dubbo.protocol
or dubbo.provider
host
attributes, supporting IP addresses and domain names. However, the registered IP address and listening IP address will be the same value.host
configuration in dubbo.protocol
or dubbo.provider
.