alibaba / nacos

an easy-to-use dynamic service discovery, configuration and service management platform for building cloud native applications.
https://nacos.io
Apache License 2.0
30.35k stars 12.86k forks source link

Does nacos support to register a instance with host name? #963

Closed riyueshiwang closed 5 years ago

riyueshiwang commented 5 years ago

Issue Description

Type: feature request

Describe what happened (or what feature you want)

I used host name instead of ip to register instance while using nacos, i got this error as follows. Does nacos support to register a instance with host name?

curl -X POST http://ip:8848/nacos/v1/ns/instance?serviceName=nacos.test.1\&ip=mesos-slave-online717-bjdxt9.cloud.xxx\&port=8888
instance format invalid:mesos-slave-online717-bjdxt9.cloud.xxx:8888:unknown:DEFAULT_1.0_true_false_DEFAULT

Describe what you expected to happen

As we all use host name instead of ip, I expect to register and update the instance with host name.

How to reproduce it (as minimally and precisely as possible)

As describe above.

Tell us your environment

nacos_1.0.0_rc2

Anything else we need to know?

nkorange commented 5 years ago

@riyueshiwang What is the need of registering hostname? Why not IP?

riyueshiwang commented 5 years ago

@nkorange Now we use host name like this 'mesos-slave-online717-bjdxt9.cloud.xxx' in our company. It's not easy to get the actural IP for some reason. Before we used eureka1.x to register and it worked, and now we expect to change our registry from eureka to nacos.

nkorange commented 5 years ago

@riyueshiwang You have a good point, it will be supported in the next one or two version.

Jnoee commented 5 years ago

能否增加一个配置参数,让用户可以指定是否优先使用hostname映射的ip地址?即优先使用 InetAddress.getLocalHost() 获取的ip地址。

Albert-Hugo commented 5 years ago

@nkorange I would like to try this. Could you help me to start this ?

nkorange commented 5 years ago

@Albert-Hugo Great, first please get familiar with the code in naming module, you can start with the class 'Instance'.

Albert-Hugo commented 5 years ago

@nkorange Ok, thank you.

Albert-Hugo commented 5 years ago

@nkorange after I change some code and try to build project and then I run this command 'mvn install -DskipTests=true -Dmaven.javadoc.skip=true -B -V' . It shows this error message. 'PMD Failure: com.alibaba.nacos.naming.core.Instance:300 Rule:UndefineMagicConstantRule Priority:3 魔法值【":"】.' .

Where should I define this magic constant to fix this bug?

nkorange commented 5 years ago

@Albert-Hugo It's already defined, use UtilsAndCommons.IP_PORT_SPLITER.

Albert-Hugo commented 5 years ago

@nkorange Thanks. It is ok now. But I wonder when should I use this kind constants in the project. Because I saw some of codes that it just using plain string like I did , but it dose not break the build rule.