apache / dubbo

The java implementation of Apache Dubbo. An RPC and microservice framework.

Home Page:https://dubbo.apache.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Proposal]support hostname or domain in service discovery.

kimmking opened this issue · comments

Hello, community,
It's a nice way to support hostname or domain in service discovery, then we can gain more flexibility both developers and users.

Problems

in Dubbo, providers register their IP addresses to Registry Server like ZK/Redis etc. It will be difficult for these case:

  • case A: When a provider deployed in a vm container such as Docker, consumers in other computer can't access the IPs in container.
  • case B: Across LANs(Local Area Network),consumer can't touch another IP in different LAN.

Target

Solve above problems to support case A & B

Solution

In case A and B, usually we map a proxy port from a remote IP or Container IP to a local IP out of network box.Then if dubbo support hostname or domain in service discovery directly, then we can modify /etc/hosts to redirect consumer's requests to the proxy port to invoke Service.

Example

  • Configure Provider

Configure protocol with a new attribute host:

<dubbo:protocol name="dubbo" port="28080" host="www.example.com" />

Then we start providers, the providers will register a URL such as "dubbo://www.example.com:28080/com.test.HelloService" to registry servers.
We also can config the host param in Service Config or Registry Config.

  • Configure Consumer

Assume 10.1.1.3 is the mapping proxy IP for real Provider IP.

Nothing need to configure except opening /etc/hosts and adding one line:
www.example.com 10.1.1.3

And then we can start consumers.

In docker ,you can use net=host to resolve case A or you can use same brige.
Also, you can use @Reference url to resolve your case B

@chutian52 your suggestion can work well for a little part of cases.

I agree this proposal about static resolution for registry service.

It can be achieved by extending the registry service but also should add more property for the referenceBean about the static host about the service.

+1. In a morden cluster environment, it would be more frequently to expand/shrink the cluster than expected. We should support putting name instead of static IP addr into the registry center.

commented

Dubbo目前已支持Provider将自身的host注册到注册中心,注册中心可以根据host自动获取服务的IP。

  1. 在provier 的xml配文件中配置provider的host值。
    <dubbo:protocol name="dubbo" port="20880" host="localhost"/>
  2. ContextFilter中通过getIpByHost方法根据provider的host获得获取provider的IP:
    NetUtils.getIpByHost()方法

您可以尝试一下

Dubbo has supported Providers to register their host to the registry server, and registry server can automatically get the IP by host name.
Firstly config the host name of provider in the xml configuration file, the configuration can be: <dubbo:protocol name="dubbo" port="20880" host="localhost"/>.
Then ContextFilter obtains the IP of provider through the NetUtil.getIpByHost method. You could try like this.

I think this proposal can lead to another question that how can we use dubbo on a kubernetes cluster. There are some scenarios that kube-dns provides a service-name to pod mapping, and users want to using Dubbo to call a service(in dubbo) by a service-name(in k8s).

set host=service-name for purpose? @lisirrx

I agree with @lamianer , today's Dubbo has already support configuring host like this:

<dubbo:protocol name="dubbo" port="20880" host="localhost"/>

If Zookeeper is used as registry center, then the following URL will be registered as provider:

[zk: localhost:2181(CONNECTED) 2] ls /dubbo/org.apache.dubbo.demo.DemoService/providers
[dubbo%3A%2F%2Flocalhost%3A20880%2Forg.apache.dubbo.demo.DemoService%3Fanyhost%3Dfalse%26application%3Ddemo-provider%26bean.name%3Dorg.apache.dubbo.demo.DemoService%26default.deprecated%3Dfalse%26default.dynamic%3Dfalse%26default.export%3Dtrue%26default.register%3Dtrue%26deprecated%3Dfalse%26dubbo%3D2.0.2%26dynamic%3Dfalse%26export%3Dtrue%26generic%3Dfalse%26interface%3Dorg.apache.dubbo.demo.DemoService%26methods%3DsayHello%26pid%3D73653%26register%3Dtrue%26release%3D%26side%3Dprovider%26timestamp%3D1551765990677]