探索 Nano 分布式(集群)示例(Distributed Chat)

简介: 探索 Nano 分布式(集群)示例(Distributed Chat)

示例仓库


笔者改过的官方示例:distributed-chat


探索


我们进入 3-distributed-chat


启动主服务器


用来管理或者调度集群中的其他服务器。

首先编译一下:


go build -o distributed


然后:


# 它的监听地址是 127.0.0.1:34567,同时也是 gRPC 服务器地址
# 它对外提供了两个服务:
# TopicService.NewUser ->> 处理来自网关的新用户请求的公共逻辑等
# TopicService.Stats ->> 集群机器服务调用统计等等
# 说白了就是 Component 里面的两个 hanlder
./distributed master --listen "127.0.0.1:34567"


启动聊天服务器并让它加入到 cluster


真正的游戏业务逻辑服务


# --master 127.0.0.1:34567 远程主服务器地址
# 它的监听地址是 127.0.0.1:34580,同时也是 gRPC 服务器地址
# 它对外提供了两个服务:
# RoomService.JoinRoom ->> 将客户端的 session 加入 Group 统一管理
# RoomService.SyncMessage ->> 广播消息,就是调用 Group 管理的 session,写信息到它们给自的 websocket 连接
./distributed chat --master "127.0.0.1:34567" --listen "127.0.0.1:34580"


启动网关服务器并让它加入到 cluster


客户端真正要连接的入口地址:


# -gate-address "127.0.0.1:34590" 这个就是客户端 websocket 连接要连接的地址
# 它的监听地址是 127.0.0.1:34570,同时也是 gRPC 服务器地址
# 它对外提供了两个服务:
# BindService.Login # 鉴权方面到处理
# BindService.BindChatServer # 直接绑定到具体到聊天服务器
./distributed gate --master "127.0.0.1:34567" --listen "127.0.0.1:34570" --gate-address "127.0.0.1:34590"


远程服务 Remote Service


集群上的每台服务器,通过 Master 节点注册后,都会把除自己以外的集群中其它节点提供的服务注册为自己的 Remote Service。


所以当我们客户端调用 starx.notify('RoomService.SyncMessage'...,其实网关服务器会调用它的 Remote Service,最终会转到 Chat Server 节点。


具体流程


http://127.0.0.1:12345/web/

用户加入房间:BindService.Login(Gate Server) -> TopicService.NewUser(Master Server) -> RoomService.JoinRoom(Chat Server)

用户发送消息:Gate Server -> RoomService.SyncMessage(Chat Server)


相关文章
|
5月前
|
数据库
分布式集群时钟同步问题及解决方案
分布式集群时钟同步问题及解决方案
194 1
|
5月前
|
算法 Linux
分布式系列教程(14) -分布式协调工具Zookeeper(集群选举策略)
分布式系列教程(14) -分布式协调工具Zookeeper(集群选举策略)
57 0
|
2月前
|
Java Linux 开发工具
Centos7搭建minio分布式集群
Centos7搭建minio分布式集群
|
3月前
|
存储 负载均衡 大数据
【分布式】集群和分布式
【1月更文挑战第25天】【分布式】集群和分布式
|
3月前
|
存储 分布式计算 负载均衡
集群与分布式:区别与联系
集群与分布式:区别与联系
73 0
|
3月前
|
存储 Kubernetes Cloud Native
云原生离线工作流编排利器 -- 分布式工作流 Argo 集群
云原生离线工作流编排利器 -- 分布式工作流 Argo 集群
105122 2
|
3月前
|
数据库 OceanBase
OceanBase数据库是一个分布式集群产品,在部署时对硬件资源有特定的需求
OceanBase数据库是一个分布式集群产品,在部署时对硬件资源有特定的需求【1月更文挑战第12天】【1月更文挑战第56篇】
29 2
|
3月前
集群和分布式
集群和分布式
|
5月前
|
Linux
分布式系列教程(37) -Linux下搭建ElasticSearch集群
分布式系列教程(37) -Linux下搭建ElasticSearch集群
39 1
分布式系列教程(37) -Linux下搭建ElasticSearch集群
|
5月前
|
存储 负载均衡 算法
分布式系列教程(36) -ElasticSearch集群原理
分布式系列教程(36) -ElasticSearch集群原理
44 0

热门文章

最新文章