MCPcopy
hub / github.com/fagongzi/manba / createServer

Function createServer

examples/server.go:8–50  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

6)
7
8func createServer() error {
9 c, err := getClient()
10 if err != nil {
11 return err
12 }
13
14 sb := c.NewServerBuilder()
15 // 必选项
16 sb.Addr("127.0.0.1:8080").HTTPBackend().MaxQPS(100)
17
18 // 健康检查,可选项
19 // 每个10秒钟检查一次,每次检查的超时时间30秒,即30秒后端Server没有返回认为后端不健康
20 sb.CheckHTTPCode("/check/path", time.Second*10, time.Second*30)
21
22 // 熔断器,可选项
23 // 统计周期1秒钟
24 sb.CircuitBreakerCheckPeriod(time.Second)
25 // 在Close状态60秒后自动转到Half状态
26 sb.CircuitBreakerCloseToHalfTimeout(time.Second * 60)
27 // Half状态下,允许10%的流量流入后端
28 sb.CircuitBreakerHalfTrafficRate(10)
29 // 在Half状态,1秒内有2%的请求失败了,转换到Close状态
30 sb.CircuitBreakerHalfToCloseCondition(2)
31 // 在Half状态,1秒内有90%的请求成功了,转换到Open状态
32 sb.CircuitBreakerHalfToOpenCondition(90)
33
34 id, err := sb.Commit()
35 if err != nil {
36 return err
37 }
38
39 fmt.Printf("server id is: %d", id)
40
41 // 把这个server加入到cluster 1
42 c.AddBind(1, id)
43
44 // 把这个server从cluster 1 移除
45 c.RemoveBind(1, id)
46
47 // 加入到cluster 2
48 c.AddBind(2, id)
49 return nil
50}
51
52func updateServer(id uint64) error {
53 c, err := getClient()

Callers

nothing calls this directly

Calls 14

AddrMethod · 0.95
CheckHTTPCodeMethod · 0.95
CommitMethod · 0.95
getClientFunction · 0.85
MaxQPSMethod · 0.80
HTTPBackendMethod · 0.80
NewServerBuilderMethod · 0.65

Tested by

no test coverage detected