Skip to content

Commit

Permalink
fix:优化example (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
chuntaojun authored Aug 13, 2024
1 parent b049688 commit 6f87eaa
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
4 changes: 2 additions & 2 deletions examples/quickstart/README-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ go build -o consumer

#### HTTP调用

执行http调用,其中`${app.port}`替换为consumer的监听端口(默认为16011)。
执行http调用,其中`${app.port}`替换为consumer的监听端口(默认为 18080 )。

```shell
curl -L -X GET 'http://localhost:${app.port}/echo?value=hello_world''
curl -H 'uid: 12313' -L -X GET 'http://localhost:${app.port}/echo?value=hello_world'
```

预期返回值:`echo: hello_world`
4 changes: 2 additions & 2 deletions examples/quickstart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ Login into polaris console, and check the instances in Service `EchoServerGRPC`.

#### Invoke by http call

Invoke http call,replace `${app.port}` to the consumer port (16011 by default).
Invoke http call,replace `${app.port}` to the consumer port (18080 by default).
```shell
curl -L -X GET 'http://localhost:47080/quickstart/feign?msg=hello_world''
curl -L -X GET 'http://localhost:${app.port}/echo?value=hello_world'
```

expect:`echo: hello_world`
11 changes: 7 additions & 4 deletions examples/quickstart/consumer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,14 @@ func main() {
}

ctx := metadata.NewIncomingContext(context.Background(), metadata.MD{})
ctx = metadata.AppendToOutgoingContext(ctx, "uid", r.Header.Get("uid"))

// 请求时设置本次请求的负载均衡算法
ctx = polaris.RequestScopeLbPolicy(ctx, api.LBPolicyRingHash)
ctx = polaris.RequestScopeLbHashKey(ctx, r.Header.Get("uid"))
if len(r.Header.Get("uid")) != 0 {
ctx = metadata.AppendToOutgoingContext(ctx, "uid", r.Header.Get("uid"))
// 请求时设置本次请求的负载均衡算法
ctx = polaris.RequestScopeLbPolicy(ctx, api.LBPolicyRingHash)
ctx = polaris.RequestScopeLbHashKey(ctx, r.Header.Get("uid"))
}

resp, err := echoClient.Echo(ctx, &pb.EchoRequest{Value: value})
log.Printf("send message, resp (%v), err(%v)", resp, err)
if nil != err {
Expand Down

0 comments on commit 6f87eaa

Please sign in to comment.