Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add service registration & service discovery & load balancing #182

Merged
merged 2 commits into from
Aug 9, 2022
Merged

feat: add service registration & service discovery & load balancing #182

merged 2 commits into from
Aug 9, 2022

Conversation

li-jin-gou
Copy link
Member

@li-jin-gou li-jin-gou commented Aug 7, 2022

What type of PR is this?

feat

What this PR does / why we need it (English/Chinese):

  • en: add service registration & service discovery & load balancing
  • ch: 添加服务注册注册 & 服务发现 & 负载均衡

Which issue(s) this PR fixes:

example:

https://github.com/li-jin-gou/nacos-demo/tree/main/example

  • server
                addr := "127.0.0.1:8889"
		r := nacos_demo.NewNacosRegistry(cli)
		h := server.Default(
			server.WithHostPorts(addr),
			server.WithRegistry(r, &registry.Info{
				ServiceName: "hertz.test.demo",
				Addr:        utils.NewNetAddr("tcp", addr),
				Weight:      10,
				Tags:        nil,
			}))
		h.GET("/ping", func(c context.Context, ctx *app.RequestContext) {
			ctx.JSON(consts.StatusOK, utils.H{"ping": "pong2"})
		})
		h.Spin()
  • client:
	r := nacos_demo.NewNacosResolver(naocsCli)
	cli.Use(sd.Discovery(r))
	for i := 0; i < 10; i++ {
		status, body, err := cli.Get(context.Background(), nil, "http://hertz.test.demo/ping", config.WithSD(true))
		if err != nil {
			hlog.Fatal(err)
		}
		hlog.Infof("code=%d,body=%s", status, string(body))
	}
2022/07/26 13:52:47.310617 main.go:46: [Info] code =200, body ={"ping":"pong2"}
2022/07/26 13:52:47.311019 main.go:46: [Info] code = 200, body ={"ping":"pong1"}
2022/07/26 13:52:47.311186 main.go:46: [Info] code = 200, body ={"ping":"pong1"}
2022/07/26 13:52:47.311318 main.go:46: [Info] code = 200, body ={"ping":"pong1"}
2022/07/26 13:52:47.311445 main.go:46: [Info] code = 200, body ={"ping":"pong1"}
2022/07/26 13:52:47.311585 main.go:46: [Info] code = 200, body ={"ping":"pong2"}
2022/07/26 13:52:47.311728 main.go:46: [Info] code = 200, body ={"ping":"pong1"}
2022/07/26 13:52:47.311858 main.go:46: [Info] code = 200, body ={"ping":"pong1"}
2022/07/26 13:52:47.311977 main.go:46: [Info] code = 200, body ={"ping":"pong1"}
2022/07/26 13:52:47.312107 main.go:46: [Info] code = 200, body ={"ping":"pong1"}

li-jin-gou and others added 2 commits August 8, 2022 18:06
* feat: add service discovery

* refactor: package

Change-Id: I1cc0faec424db8a65e101f301185d62defcd44ce

Co-authored-by: kinggo <lilong.21@bytedance.com>
Copy link
Member

@welkeyever welkeyever left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@welkeyever welkeyever changed the title feat: add service discovery feat: add service registration & service discovery & load balancing Aug 9, 2022
@welkeyever welkeyever merged commit 74dde60 into cloudwego:develop Aug 9, 2022
@li-jin-gou li-jin-gou deleted the feat/service_discovery2 branch September 25, 2022 06:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants