Skip to content
Browse files
Merge pull request #293 from ZhangYaoFu/consul_naming_service
  • Loading branch information
jamesge committed Apr 18, 2018
2 parents dd5cc23 + a315ea4 commit 680538df385b8f6c4e309aab054d83033c4d26f5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
@@ -96,6 +96,18 @@ BNS是百度内常用的名字服务,比如bns://rdev.matrix.all,其中"bns"

连接一个域名下所有的机器, 例如 ,注意连接单点的Init(两个参数)虽然也可传入域名,但只会连接域名下的一台机器。

### consul://\<service-name\>



除了对consul的首次请求,后续对consul的请求都采用[long polling](的方式,即仅当服务列表更新或请求超时后consul才返回结果,这里超时时间默认为60s,可通过-consul\_blocking\_query\_wait\_secs来设置。

若consul返回的服务列表[响应格式](有错误,或者列表中所有服务都因为地址、端口等关键字段缺失或无法解析而被过滤,consul naming server会拒绝更新服务列表,并在一段时间后(默认500ms,可通过-consul\_retry\_interval\_ms设置)重新访问consul。

如果consul不可访问,服务可自动降级到file naming service获取服务列表。此功能默认关闭,可通过设置-consul\_enable\_degrade\_to\_file\_naming\_service来打开。服务列表文件目录通过-consul \_file\_naming\_service\_dir来设置,使用service-name作为文件名。该文件可通过consul-template生成,里面会保存consul不可用之前最新的下游服务节点。当consul恢复时可自动恢复到consul naming service。

### 名字服务过滤器

@@ -96,6 +96,18 @@ Servers are directly written after list://, separated by comma. For example: "li

Connect all servers under the domain, for example: Note: although Init() for connecting single server(2 parameters) accepts hostname as well, it only connects one server under the domain.

### consul://\<service-name\>

Get a list of servers with the specified service-name through consul. The default address of consul is localhost:8500, which can be modified by setting -consul\_agent\_addr in gflags. The connection timeout of consul is 200ms by default, which can be modified by -consul\_connect\_timeout\_ms.

By default, [stale]( and passing(only servers with passing in statuses are returned) are added to [parameters of the consul request]((, which can be modified by -consul\_url\_parameter in gflags.

Except the first request to consul, the follow-up requests use the [long polling]( feature. That is, the consul responds only when the server list is updated or the request times out. The timeout defaults to 60 seconds, which can be modified by -consul\_blocking\_query\_wait\_secs.

If the server list returned by the consul does not follow [response format](, or all servers in the list are filtered because the key fields such as the address and port are missing or cannot be parsed, the server list will not be updated and the consul service will be revisited after a period of time(default 500ms, can be modified by -consul\_retry\_interval\_ms).

If consul is not accessible, the naming service can be automatically downgraded to file naming service. This feature is turned off by default and can be turned on by setting -consul\_enable\_degrade\_to\_file\_naming\_service. After downgrading, in the directory specified by -consul\_file\_naming\_service\_dir, the file whose name is the service-name will be used. This file can be generated by the consul-template, which holds the latest server list before the consul is unavailable. The consul naming service is automatically restored when consul is restored.

### Naming Service Filter

Users can filter servers got from the NamingService before pushing to LoadBalancer.

0 comments on commit 680538d

Please sign in to comment.