当前位置:网站首页>[gatewaysessioninactiveevent event] 1 Connect your own client disconnect
[gatewaysessioninactiveevent event] 1 Connect your own client disconnect
2022-06-12 14:36:00 【Understand the principle + good code skills】
1. Must be in their own process to listen to
2.GatewayRouteHandler Of channelInactive The central supervisor heard that his client was disconnected , Will throw an asynchronous event in it
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
var session = SessionUtils.getSession(ctx);
if (session == null) {
return;
}
var sid = session.getSid();
var uid = (Long) session.getAttribute(AttributeType.UID);
// Asynchronous events
EventBus.asyncSubmit(GatewaySessionInactiveEvent.valueOf(sid, uid == null ? 0 : uid.longValue()));
super.channelInactive(ctx);
}
3. stay GatewayController.java Just listen to the event and handle it
@Component
public class GatewayController {
@EventReceiver
public void onGatewaySessionInactiveEvent(GatewaySessionInactiveEvent event) {
var sid = event.getSid();
var uid = event.getUid();
// If the player is not logged in , You don't do anything
if (uid <= 0) {
return;
}
// Listen for client disconnect
var packet = LogoutRequest.valueOf();
var loadBalancer = NetContext.getConfigManager().consumerLoadBalancer();
// This is consumer Connected to provider, therefore : Yes, it can be found consumer And provider Connection between session Of . Tell directly through this
var consumerSession = loadBalancer.loadBalancer(packet, uid);
// Player logout
var gatewayAttachment = new GatewayAttachment(sid, uid);
// true: The client is disconnected
gatewayAttachment.setClient(true);
// rpc Tell all servers , This person dropped the line
NetContext.getRouter().send(consumerSession, packet, gatewayAttachment);
}
}4. stay gateway Of application.xml Multiple consumers are configured in
<net:consumer load-balancer="consistent-hash">
<net:module name="tankHome"/>
<net:module name="tankCache"/>
</net:consumer>It should be telling them LoginOut Player client for
5. stay home Of LoginController There's monitoring
@PacketReceiver
public void atLogoutRequest(Session session, LogoutRequest request, GatewayAttachment gatewayAttachment) {
logger.info("c[{}][{}] Players quit the game ", gatewayAttachment.getUid(), gatewayAttachment.getSid());
var uid = gatewayAttachment.getUid();
var player = playerEntityCaches.load(uid);
player.sid = 0;
player.session = null;
playerEntityCaches.update(player);
}边栏推荐
- Markdown edit
- [wp][入门]攻防世界-game
- 【Environment】1. Get the configuration in YML through the environment in the configuration class
- 完美收官|详解 Go 分布式链路追踪实现原理
- PMP敏捷知识点
- Socket model of punctual atom stm32f429 core board
- Tu oses le croire? Il m'a fallu deux jours pour développer un système de gestion.
- Reverse order of Excel
- 【LocalDate LocalTime LocalDateTime】1. Using immutability to achieve thread safety 2 Current date, current time, current date time 3 Since the time zone is not considered, you need to add 8 hours to th
- Perfect ending | detailed explanation of the implementation principle of go Distributed Link Tracking
猜你喜欢

Tu oses le croire? Il m'a fallu deux jours pour développer un système de gestion.

Player actual combat 13 create qtopengl project to promote window control and reload qoopenglwedge

PMP agile knowledge points
![[wechat applet] 4 Introduction to wechat developer tools](/img/9d/0d6c5cc675fb70dde98b25649bd8d8.jpg)
[wechat applet] 4 Introduction to wechat developer tools

Printing colored messages on the console with printf

Why do Chinese programmers change jobs?

G++ error in compiling Win32 program: undefined reference to '__ imp_ GetStockObject‘

ADB command (2) use monkey to test

junit测试套件方法整理(方法二不太好用)

Configuring OSPF pseudo connection for Huawei devices
随机推荐
Redis data deletion policy in 2022
C secret arts script Chapter 5 (structure) (Section 1)
Conversion of player's actual 10 pixel format and size
[wechat applet] 5 Applet structure directory
数据的收集
En langage C, la fonction principale appelle une autre fonction et assemble le Code pour comprendre
Tcp/ip network communication knowledge record
PMP agile knowledge points
Autofac初学(1)
The igatewayloadbalancer interface implements routing. Otherwise, it follows Sid routing
Player practice 18 xresample
Reverse order of Excel
华为设备配置OSPF伪连接
QT multi thread drawing and real-time refreshing method
QT database realizes page turning function
Markdown edit
Vs2012: cannot assign a value of type 'char *' to an entity of type 'lpwstr'
Simple code implementation of addition, subtraction, multiplication and division calculator
Xshell (I) is missing mfc110u DLL file resolution
Visual positioning guidance system for industrial manipulator (robot)