Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Proposal]support hostname or domain in service discovery. #2043

Closed
kimmking opened this issue Jul 7, 2018 · 9 comments
Closed

[Proposal]support hostname or domain in service discovery. #2043

kimmking opened this issue Jul 7, 2018 · 9 comments
Milestone

Comments

@kimmking
Copy link
Member

kimmking commented Jul 7, 2018

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.

@chutian52
Copy link

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

@chickenlj chickenlj added this to the 2.7.0 milestone Jul 9, 2018
@kimmking
Copy link
Member Author

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

@Jeff-Lv
Copy link
Contributor

Jeff-Lv commented Jul 18, 2018

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.

@beiwei30
Copy link
Member

+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.

@caneo
Copy link

caneo commented Aug 28, 2018

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()方法

您可以尝试一下

@lamianer
Copy link

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.

@lisirrx
Copy link

lisirrx commented Aug 28, 2018

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).

@chutian52
Copy link

set host=service-name for purpose? @lisirrx

@chickenlj chickenlj modified the milestones: 2.7.0, 2.7.1 Jan 15, 2019
@beiwei30
Copy link
Member

beiwei30 commented Mar 5, 2019

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]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants