iohao / ioGame

无锁异步化、事件驱动架构设计的 java netty 网络编程框架; 轻量级,无需依赖任何第三方中间件或数据库就能支持集群、分布式; 适用于网络游戏服务器、物联网、内部系统及各种需要长连接的场景; 通过 ioGame 你可以很容易的搭建出一个集群无中心节点、集群自动化、分布式的网络服务器;FXGL、Unity、UE、Cocos Creator、Godot、Netty、Protobuf、webSocket、tcp、socket;java Netty 游戏服务器框架;

Home Page:http://game.iohao.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

分布式总线使用

molin7596 opened this issue · comments

commented

你的问题 | 使用场景

描述你遇到的问题,或使用场景(询问框架能否满足此类需求)
分布式总线使用 , 使用 flowContext.fire() 发送事件给订阅者, 获取EventBus is null
java.lang.NullPointerException: Cannot invoke "com.iohao.game.action.skeleton.eventbus.EventBus.fire(com.iohao.game.action.skeleton.eventbus.EventBusMessage)" because "eventBus" is null

预期值

期望的预期值

实际值

实际值

复现步骤

描述复现步骤,并提供复现 demo

@Override
    public void into(UserSession userSession) {
        log.info("玩家上线 userId: {} -- channelId: {} ", userSession.getUserId(), userSession.getUserChannelId());
        log.info("当前在线玩家数量: {}", this.userSessions.countOnline());

        RequestMessage requestMessage = ExternalCodecKit.createRequest();
        HeadMetadata headMetadata = requestMessage.getHeadMetadata();
        headMetadata.setCmdInfo(CmdInfo.of(AuthCmd.CMD, AuthCmd.ONLINE));

        ExternalCodecKit.employ(requestMessage, brokerClient);
        userSession.employ(requestMessage);
        try {
            brokerClient.oneway(requestMessage);
        } catch (Exception e) {
            log.error("转发失败:", e);
        }
    }
@ActionMethod(AuthCmd.ONLINE)
    public void online(CustomFlowContext flowContext) {
        // 上线
        authService.online(flowContext.getUserId());
        // 发布角色上线事件
        CharacterOnlineEventMessage eventMessage = new CharacterOnlineEventMessage();
        eventMessage.characterId = flowContext.getUserId();
        flowContext.fire(eventMessage);
    }

版本

  • ioGame version: 21.6

你的代码看上去是没有问题的,可以提供一个可运行的 demo 吗。

commented

难以复现 我调整了模块结构然后无法复现了

commented

我把逻辑服的相关配置 ,配置成公共 starter模块 就会出现这个 获取 EventBus 为null

commented

common-server-starter 中 只有一个 spring-boot-starter 和 bolt-client, 我把starter中的代码移动到任意一个逻辑服的包下面 都没有问题, 但是我引入这个 starter 然后 就会开始概率出现 获取 EventBus 为null

commented

我单独写个demo 无法复现 ,这种问题 有可能是 其他 某个未知 jar包 导致的问题吗?

commented

@iohao 大佬 这种问题 有什么头绪吗

common-server-starter 中 只有一个 spring-boot-starter 和 bolt-client, 我把starter中的代码移动到任意一个逻辑服的包下面 都没有问题, 但是我引入这个 starter 然后 就会开始概率出现 获取 EventBus 为null

你从这里断点跟一下吧。