In Dubbo, Provider mainly does two things when it starts
host
when host
is not set in dubbo
?host
of the service in dubbo
, can we use hostname or domain instead of 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 configured. What is the host set at this time?
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 value is as follows:
Besides, you can configure host
through dubbo.protocol
or dubbo.provider
’s host
property, which supports IP address and domain name, as follows:
...
<dubbo:protocol name="dubbo" port="20890" host="www.example.com"/>
...
See dubbo set host by environment variable
Some deployment scenarios need to dynamically specify the address of the service registration, such as the docker bridge network mode to specify the registration host ip to achieve external network communication. dubbo provides two pairs of system properties in the startup phase, which are used to set the ip and port addresses for external communication.
The above four configuration items are optional. If you do not configure dubbo, it will automatically obtain the ip and port. Please choose the configuration flexibly according to the specific deployment scenario. dubbo supports multiple protocols. If an application exposes multiple different protocol services at the same time, and you need to specify an ip or port for each service separately, please add a protocol prefix before the above attributes. Such as:
PORT_TO_REGISTRY or IP_TO_REGISTRY will not be used as default PORT_TO_BIND or IP_TO_BIND, but the reverse is true. Such as:
PORT_TO_REGISTRY=20881
and IP_TO_REGISTRY=30.5.97.6
, then PORT_TO_BIND
and IP_TO_BIND
will not be affectedPORT_TO_BIND=20881
and IP_TO_BIND=30.5.97.6
, then default PORT_TO_REGISTRY=20881
and IP_TO_REGISTRY=30.5.97.6
host
through the host
attribute of dubbo.protocol
or dubbo.provider
, and support IP addresses and domain names. But at this time, the IP address registered to the registration center and the listening IP address are the same valuedubbo.protocol
or dubbo. provider
s host
configuration