当前位置:网站首页>Producers (send syncask requests) and consumers (with xxxask monitoring and Implementation)
Producers (send syncask requests) and consumers (with xxxask monitoring and Implementation)
2022-06-12 14:36:00 【Understand the principle + good code skills】
home clothing
application.xml
<net:config id="tankHome" protocol-location="protocol.xml" generate-cs-protocol="${net.generate.cs.protocol}"
fold-protocol="${net.fold.protocol}">
<net:registry center="${registry.center}" user="${registry.user}" password="${registry.password}">
<net:address name="${registry.address.name}" url="${registry.address.url}"/>
</net:registry>
<net:provider task-dispatch="consistent-hash">
<net:module name="tankHome"/>
</net:provider>
<net:consumer load-balancer="consistent-hash">
<net:module name="tankCache"/>
</net:consumer>
</net:config>home The server makes a request
// Send asynchronously to cache clothing
NetContext.getConsumer().asyncAsk(BattleScoreAsk.valueOf(uid, score), BattleScoreAnswer.class, uid)
.whenComplete(answer -> {
logger.info("c[{}][{}] Asynchronous callback of player battle results ", gatewayAttachment.getUid(), gatewayAttachment.getSid());
// After the battle, if you get on the leaderboard , Then reward , Each point is worth one gold coin , Half a diamond
if (answer.isRankReward()) {
var currencyPo = player.getCurrencyPo();
currencyPo.setGold(currencyPo.getGold() + score);
currencyPo.setGem(currencyPo.getGem() + score / 2);
addPlayerExp(player, score);
playerEntityCaches.update(player);
NetContext.getRouter().send(session, BattleResultResponse.valueOf(score), gatewayAttachment);
NetContext.getRouter().send(session, CurrencyUpdateNotice.valueOf(currencyPo.toCurrencyVO()), gatewayAttachment);
}
});cache clothing
@PacketReceiver
public void atBattleScoreAsk(Session session, BattleScoreAsk ask) {
var playerId = ask.getPlayerId();
var score = ask.getScore();
// If not on the list , Go straight back to ; On the list , Insert the current score into the database
if (score <= minScore && rankLimit >= RANK_SIZE) {
NetContext.getRouter().send(session, BattleScoreAnswer.valueOf(false));
return;
}
// Get a distributed auto increment unique id
var id = MongoIdUtils.getIncrementIdFromMongoDefault(ScoreRankEntity.class);
// Insert database
OrmContext.getAccessor().insert(ScoreRankEntity.valueOf(id, playerId, TimeUtils.now(), score));
NetContext.getRouter().send(session, BattleScoreAnswer.valueOf(true));
}边栏推荐
- Communication flow analysis
- 阿里建议所有 POJO 类属性使用包装类,但这些坑你有注意到吗?
- Autofac初学(1)
- Player actual combat 23 decoding thread
- What is automatic bidding? What are its advantages?
- 【Calendar】1. For globalization 2 But only date can be formatted by SDF 3 Month to -1 4 Week from Sunday is the first day
- Player practice 20 unpacking thread
- Notepad common settings
- Player practice 19 xaudio turn on audio
- How to use Android studio to create an Alibaba cloud Internet of things app
猜你喜欢

What is automatic bidding? What are its advantages?
![[wp][入门]攻防世界-game](/img/07/1ea54d14ba3caca25a68786d5be4a6.png)
[wp][入门]攻防世界-game

Mobileone: the mobile terminal only needs 1ms of high-performance backbone. You deserve it!

【OCR】AspriseOCR C# 英文、数字识别(中文不行)

Player practice 17 xvideowidget

selenium之元素定位

工业机械臂(机器人)视觉定位引导系统

Dynamic search advertising intelligent search for matching keywords

webdriver入门

How to use Android studio to create an Alibaba cloud Internet of things app
随机推荐
Tcp/ip network communication knowledge record
Player practice 17 xvideowidget
ADB control installation simulator
recursive learning
NetCore结合CAP事件总线实现分布式事务——入门(1)
C secret arts script Chapter 2 (detailed explanation of pointer) (Section 2)
For cross-border e-commerce, the bidding strategy focusing more on revenue - Google SEM
C secret script Chapter 1: data storage (in-depth analysis)
Player practice 26 adding slider and window maximization
En langage C, la fonction principale appelle une autre fonction et assemble le Code pour comprendre
The difference between parameter and argument in C language
Notepad common settings
Sorting out the differences between ABS () and Fabs () in C language
你敢信?开发一个管理系统我只用了两天
Leetcode 2185. Counts the string containing the given prefix
Configuring OSPF pseudo connection for Huawei devices
[MySQL] basic database operation
Can you believe it? It took me only two days to develop a management system
QT database realizes page turning function
Reverse order of Excel