From 6f87eaa613e6717ca09a5af6defe3cc5e387ee3b Mon Sep 17 00:00:00 2001 From: liaochuntao Date: Tue, 13 Aug 2024 16:10:43 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BC=98=E5=8C=96example=20(#70)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/quickstart/README-zh.md | 4 ++-- examples/quickstart/README.md | 4 ++-- examples/quickstart/consumer/main.go | 11 +++++++---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/examples/quickstart/README-zh.md b/examples/quickstart/README-zh.md index 8328c9d..f234106 100644 --- a/examples/quickstart/README-zh.md +++ b/examples/quickstart/README-zh.md @@ -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` \ No newline at end of file diff --git a/examples/quickstart/README.md b/examples/quickstart/README.md index fd84618..95f6dad 100644 --- a/examples/quickstart/README.md +++ b/examples/quickstart/README.md @@ -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` \ No newline at end of file diff --git a/examples/quickstart/consumer/main.go b/examples/quickstart/consumer/main.go index 78d79dc..f8494c8 100644 --- a/examples/quickstart/consumer/main.go +++ b/examples/quickstart/consumer/main.go @@ -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 {