Giter Club home page Giter Club logo

netty-chat's Introduction

netty-chat

Protocol:

Length Header Actual Content
4byte 8byte data length

Header:

version 协议版本号,当协议有改变,以及entity属性有改变时通过版本号进行序列化操作。
handlerId 业务分发处理,IMHandlerManager.find(handlerId),通过handler去处理客户端请求。
commandId 命令动作处理,IMHandler.dispatch(IMConnection, IMRequest),对IMRequest处理,IMConnection应答或者kill。
reserved 数据序列处理,对Actual Content进行加解密类型,以及序列化反序列化方式。

客户端请求,通过readEntity读取对象数据,以游标方式读取,可以连续读取多个Entity

IMRequest:

readEntity(IMSerializer.class);

服务端应答,通过writeEntity写入对象数据,可以连续写入多个Entity

IMResponse:

writeEntity(IMSerializer);

长连接,发送数据内容,控制客户端连接

IMConnection:

sendResponse(imResponse);
kill();

业务分发处理

IMHandler:

dispatch(IMConnection, IMRequest)

业务处理流程

Received:
findHandler(id).dispatch() -> UserHandler

UserHandler.dispatch()
switch(cmdId)
// doCommand

UserHandler <- UserService <- UserRepository

  • 水平扩展设计思路,登录后返回token,并分配chat-server,再进行loginChannel,通过token建立连接,以chat-server持有客户连接上的IMConnection。
  • 每个chat-server都有一个node cache,保存当前连接用户的在线信息,如果当前node中不存在,在全局nodeAll中获取是否在线信息。
  • 并加入chat-route模块,在chat-server启动时注册服到route中,以长连接通信(断开时无限重试连接),做send/notify操作。
  • 如果发送消息时from == to服务器,直接做业务处理,再做应答客户端。
  • 如果发送消息时from != to服务器,通过chat-route做send操作,自动转发到相应服务器,再做业务处理,然后应答相应客户端。

序列图

image image image

netty-chat's People

Contributors

tonybase avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.