forked from fionawp/service-registration-and-discovery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
design.txt
113 lines (61 loc) · 2.32 KB
/
design.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
consule
v1/services/serviceName
service name
ip
port
desc
updatetime
createTime
ttl
{
"ip":"127.0.0.1",
"port":"2222",
"desc":"test",
"ttl":5
}
启动可以指定配置文件
curl --request PUT -d '{"code":"i love u"}' http://127.0.0.1:8500/v1/test/test
curl -v 'http://127.0.0.1:8500/v1/test/test'
curl http://localhost:8500/v1/kv/?recurse [{"CreateIndex":97,"ModifyIndex":97,"Key":"web/key1","Flags":0,"Value":"dGVzdA=="},
{"CreateIndex":98,"ModifyIndex":98,"Key":"web/key2","Flags":42,"Value":"dGVzdA=="},
{"CreateIndex":99,"ModifyIndex":99,"Key":"web/sub/key3","Flags":0,"Value":"dGVzdA=="}]
curl 127.0.0.1:8500/v1/kv/aa {"code":"iii"}
curl -X put -d '{"code":"iii"}' 127.0.0.1:8500/v1/kv/aa
起来一个consul agent
/usr/local/adinf/consul/consul agent -dev -ui -node=consul-dev -client=0.0.0.0
发现;
serviceName
http://192.168.33.11:8500/v1/kv/firstService?recurse
是一个数组
连接池
三秒一更新
连接的时候需要重试(连接的时候必须设置超时时间)
传一个 serviceName 进来 获取所有的server
遍历 servers ttl 更新时间 仍然活着的 放到连接池
1. 根据 serviceName 从连接池获取
如果是空
从 consul 里面取 过滤掉 dead ones 放到连接池 (该部分抽象出来 公用)
负载均衡待定,先随机取
2.开一个协程 每三秒 重新获取一遍 给内存的map(连接池)重新赋值
###问题:
心跳 每五秒钟 更新一次时间
每五秒钟更新一次内存
换成6s更新一次内存 还是会有空白的时候 也会有返回来的时间10s才更新一次的情况
存在内存的服务变量必须是一个进程级别的单例,对于任何请求都只有一个实例
对该实例的读写都加锁,为了防止写的时候其他任务等待的时间过长,锁的范围尽可能的缩小
并且读和写都必须是一把锁,吧锁的实例作为服务单例的一个属性来使用
## 封装上游协议 SDK
lib.Discover("test")
"test" /a
httpsdk
call("test", "/a", params)
1. service_router.Discover("test") ---> ip:port list
2. load balance(list<>()) ---> ip:port
http
3. ip:port/a --> http client
grpc
grpc.connect("host:port") *Conn
3. ip:port --> connection pool
map[string] *Conn
4. *conn->xxx()
protoc -I GrpcTest/ GrpcTest/helloworld.proto --go_out=plugins=grpc:helloworld