当前位置:网站首页>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));
}边栏推荐
猜你喜欢

How to use Android studio to create an Alibaba cloud Internet of things app

Program analysis and Optimization - 6 loop optimization

Player actual combat 22 to solve the problems of flower screen and Caton

jenkins相关

Player actual combat 14 display YUV

Reverse order of Excel

QT realize picture dragging

Redis data deletion policy in 2022

selenium之元素定位

Autofac初学(1)
随机推荐
How to use Android studio to create an Alibaba cloud Internet of things app
Markdown edit
NetCore结合CAP事件总线实现分布式事务——消息(2)
Pay attention to click and pursue more users to enter the website. What bidding strategy can you choose?
Player practice 15 xdemux and avcodecparameters
[Writeup]BUU SQL COURSE1[入门级]
Xshell (I) is missing mfc110u DLL file resolution
程序构造和解释之过程抽象
Design of PLC intelligent slave station based on PROFIBUS DP protocol
Introduction to QT reflection mechanism and signal slot mechanism
Software package for optimization scientific research field
Variable parameters
JMeter (V) pressure test of Excel file upload interface
Player practice 11 audio resampling
QT database realizes page turning function
JS (II) syntaxerror: cannot use import statement outside a module
C secret script Chapter 1: data storage (in-depth analysis)
【SimpleDateFormat】1. Conversion of date type and text type 2 Thread unsafe
Player actual combat 16 xdecode class
Getting started alicloud haas510 open board DTU (version 2.0) --510-as