跳到主要内容

Broker 游戏网关介绍

ioGame


从架构简图中,我们知道了整体架构由三部分组成,分别是 1.游戏对外服、2.游戏网关、3.游戏逻辑服,三者既可相互独立,又可相互融合。

Broker(游戏网关)在架构图位置的中间部分。

介绍

游戏网关是在架构中扮演一个中间调度者的角色,职责如下

  1. 负载均衡逻辑服,即使某个逻辑服挂掉也不会影响整个系统。
  2. 转发游戏逻辑服和游戏对外服的请求与响应。

如何安装

如果你是初次体验或想快速了解框架的,在 pom.xml 添加如下内容, run-one-netty 已经包含了游戏对外服、Broker(游戏网关)、游戏逻辑服。

pom.xml
<dependency>
<groupId>com.iohao.game</groupId>
<artifactId>run-one-netty</artifactId>
<version>${ioGame.version}</version>
</dependency>

通常在实际开发中,比较推荐的做法中单独为 Broker 创建一个模块,并在 pom.xml 中添加如下内容

see https://central.sonatype.com/artifact/com.iohao.game/bolt-broker-server

pom.xml
<dependency>
<groupId>com.iohao.game</groupId>
<artifactId>bolt-broker-server</artifactId>
<version>${ioGame.version}</version>
</dependency>

创建 Broker

  • code 3,创建 Broker 构建器。
  • code 4,设置 Broker 端口(默认 10200),也就是逻辑服连接到 Broker 的端口。
  • code 7,启动
public class BrokerServerStandaloneTest {
public static void main(String[] args) throws Exception {
BrokerServerBuilder brokerServerBuilder = BrokerServer.newBuilder()
.port(IoGameGlobalConfig.brokerPort);

BrokerServer brokerServer = brokerServerBuilder.build();
brokerServer.startup();
}
}