You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2021/04/25 10:40:52 UTC
[GitHub] [dubbo-go-samples] cjphaha commented on a change in pull request #97: add readme of game
cjphaha commented on a change in pull request #97:
URL: https://github.com/apache/dubbo-go-samples/pull/97#discussion_r619793313
##########
File path: game/README_zh.md
##########
@@ -4,10 +4,270 @@
- 示例包含 **gate** (网关服务) 和 **game** (逻辑服务) 两个服务
- 两个服务会互相 RPC 通讯 (都同时注册 **provider** 和 **consumer**)
-- **gate** 额外启动了 http 服务 (端口 **8000**), 用于手工触发 **gate** RPC调用 **game**
+- **gate** 额外启动了 http 服务 (端口 **8000**), 用于手工触发 **gate** RPC 调用 **game**
+
+> 每次 **gate** RPC调用(**Message**) **game** 后, **game** 会同步RPC调用(Send) **gate** 推送相同消息,samples中有两个服务,一个是 basketballService,一个是 jumpService,其中 jumpService 部分已经注释掉,内容和basketball 基本一致。
+
+### 概要
+
+目录说明
+
+```bash
+├── go-server-game # game模块
+│ ├── cmd # 主入口
+│ ├── conf # 配置文件
+│ ├── docker # docker-compose文件
+│ ├── pkg # provider和consumer
+│ └── tests
+├── go-server-gate # gate模块
+│ ├── cmd # 主入口
+│ ├── conf # 配置文件
+│ ├── docker # docker-compose文件
+│ ├── pkg # provider和consumer
+│ └── tests
+└── pkg
+ ├── consumer # 公共consumer
+ │ ├── game
+ │ └── gate
+ └── pojo
+```
+
+发起http服务的流程
+
+<img src="http://cdn.cjpa.top/cdnimages/image-20210423212453935.png" alt="image-20210423212453935" style="zoom:50%;" />
+
+
+
+从consumer和provider角度来看,发起一次调用的流程是这样的
+
+<img src="http://cdn.cjpa.top/cdnimages/image-20210424094134541.png" alt="image-20210424094134541" style="zoom: 33%;" />
+
+game提供了basketball服务端,gate提供了http服务端。
+
+### game模块
+
+#### server端
+
+server 端提供三个服务,message、online 及 offline,代码如下,具体的实现可以在 game/go-server-game/pkg/provider.go 中看到
+
+```go
+type BasketballService struct{}
+
+func (p *BasketballService) Online(...) (...) {
+ ...
+}
+
+func (p *BasketballService) Offline(...) (...) {
+ ...
+}
+
+func (p *BasketballService) Message(...) (...) {
+ ...
+}
+
+func (p *BasketballService) Reference() string {
+ return "gameProvider.basketballService"
+}
+```
+
+##### 配置文件
+
+ 在配置文件中注册 service,其中 gameProvider.basketballService 和 Reference 方法中声明的一致。
+
+```yml
+services:
+ "gameProvider.basketballService":
+ registry: "demoZk"
+ protocol: "dubbo"
+ interface: "org.apache.dubbo.game.BasketballService"
+ loadbalance: "random"
+ warmup: "100"
+ cluster: "failover"
+ methods:
+ - name: "Online"
+ retries: 0
+ - name: "Offline"
+ retries: 0
+ - name: "Message"
+ retries:
+```
+
+#### consumer端
+
+basketball 部分的 consumer 主要用来被 gate 调用,因此主要代码放在了 game/pkg/consumer/gate/basketball.go 中,这部分作为公共部分,consumer 代码如下
+
+```go
+type BasketballService struct {
+ Send func(ctx context.Context, uid string, data string) (*pojo.Result, error)
+}
+
+func (p *BasketballService) Reference() string {
+ return "gateConsumer.basketballService"
+}
+```
+
+在basketball中,只需要实例化一个consumer变量即可
+
+```go
+var gateBasketball = new(gate.BasketballService)
+```
+
+然后在main中注册到dubbo-go
+
+```go
+config.SetConsumerService(gateBasketball)
+```
+
+##### 配置文件
+
+```yml
+references:
+ "gateConsumer.basketballService":
+ registry: "demoZk"
+ protocol : "dubbo"
+ interface : "org.apache.dubbo.gate.BasketballService"
+ cluster: "failover"
+ methods:
+ - name: "Send"
+ retries: 0
+```
+
+由于 game 的 consumer 需要调用 gate 的provider,因此 Reference 方法返回的字符串为 gateConsumer.basketballService ,在配置文件中中 gateConsumer.basketballService 和 game/pkg/consumer/gate/basketball.go 中Reference 方法声明的一致,intreface 的值也要和 gate 的 provider 设置的一致。
Review comment:
感谢感谢,我晚上改一下😬
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org