当前位置:网站首页>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));
}边栏推荐
- Mysql之索引和视图
- JS (I) error [err\u module\u not\u found]: cannot find package 'UUID' imported
- The original Xiaoyuan personal blog project that has been around for a month is open source (the blog has basic functions, including background management)
- 华为设备配置H虚拟专用网
- selenium进阶
- Ppt cannot be opened, always prompt how to fix it
- [Writeup]BUU SQL COURSE1[入门级]
- How to realize the bidding strategy that pays more attention to transformation in the company's operation Google sem
- QT database realizes page turning function
- Why do Chinese programmers change jobs?
猜你喜欢

Player practice 17 xvideowidget

Recursive summary of learning function

Appnium (II) installation and basic use of mitmproxy

Pay attention to click and pursue more users to enter the website. What bidding strategy can you choose?

华为设备配置OSPF伪连接

TestEngine with ID ‘junit-vintage‘ failed to discover tests

QT to realize the simple use of SQLite database

C secret arts script Chapter 5 (paragraph) (Section 3)

用游戏来讲序列化与反序列化机制

Tcp/ip network communication knowledge record
随机推荐
[datetmeformatter] realize the conversion between localdatetime and text
And, or, not equal, operator
【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
C secret script Chapter 1: data storage (in-depth analysis)
How to realize the bidding strategy that pays more attention to transformation in the company's operation Google sem
【Environment】1. Get the configuration in YML through the environment in the configuration class
Getting started alicloud haas510 open board DTU (version 2.0) --510-as
Xshell (I) is missing mfc110u DLL file resolution
PMP敏捷知识点
C magic skill Chapter 4 (detailed explanation of memory function)
JD scanning code to obtain cookies
Pay attention to click and pursue more users to enter the website. What bidding strategy can you choose?
Visual studio common shortcuts
Dynamic search advertising intelligent search for matching keywords
Word insert picture blocked by text
Reverse order of Excel
junit测试套件方法整理(方法二不太好用)
Autofac初学(1)
Player actual combat 13 create qtopengl project to promote window control and reload qoopenglwedge
[MySQL] basic database operation