use of com.code.server.constant.kafka.KafkaMsgKey in project summer by foxsugar.
the class UserServiceMsgConsumer method listen3.
@KafkaListener(id = "clubService", topicPattern = "clubService")
public void listen3(ConsumerRecord<String, String> record) {
String key = record.key();
String value = record.value();
KafkaMsgKey msgKey = JsonUtil.readValue(key, KafkaMsgKey.class);
JsonNode msgValue = JsonUtil.readTree(value);
ClubServiceMsgDispatch clubServiceMsgDispatch = SpringUtil.getBean(ClubServiceMsgDispatch.class);
clubServiceMsgDispatch.dispatchMsg(msgKey, msgValue);
}
use of com.code.server.constant.kafka.KafkaMsgKey in project summer by foxsugar.
the class LoginAction method test.
@RequestMapping("/")
public Map<String, Object> test() {
// RedisManager.getUserRedisService().addUserMoney("", 1);
int partition = 0;
KafkaMsgKey kafkaKey = new KafkaMsgKey();
kafkaKey.setUserId(3);
kafkaKey.setPartition(1);
String keyJson = JsonUtil.toJson(kafkaKey);
SpringUtil.getBean(MsgProducer.class).send("gamePaijiuService", kafkaKey, "hello");
Map<String, Object> params = new HashMap<>();
System.out.println("====");
return params;
}
use of com.code.server.constant.kafka.KafkaMsgKey in project summer by foxsugar.
the class UserServiceConsumer method consumer.
@Override
public void consumer(ConsumerRecord<String, String> record) {
ThreadPool.getInstance().executor.execute(() -> {
String key = record.key();
String value = record.value();
KafkaMsgKey msgKey = JsonUtil.readValue(key, KafkaMsgKey.class);
JsonNode msgValue = JsonUtil.readTree(value);
UserServiceMsgDispatch userServiceMsgDispatch = SpringUtil.getBean(UserServiceMsgDispatch.class);
userServiceMsgDispatch.dispatchMsg(msgKey, msgValue);
});
}
use of com.code.server.constant.kafka.KafkaMsgKey in project summer by foxsugar.
the class UserServiceMsgConsumer method listen2.
@KafkaListener(id = "centerTopic", topicPattern = "center_topic")
public void listen2(ConsumerRecord<String, String> record) {
ThreadPool.getInstance().executor.execute(() -> {
String key = record.key();
String value = record.value();
KafkaMsgKey msgKey = JsonUtil.readValue(key, KafkaMsgKey.class);
CenterMsgService.dispatch(msgKey, value);
});
}
use of com.code.server.constant.kafka.KafkaMsgKey in project summer by foxsugar.
the class MsgDispatch method dispatch.
public static void dispatch(ConsumerRecord<String, String> record) {
try {
logger.info(record.toString());
String key = record.key();
String value = record.value();
KafkaMsgKey msgKey = JsonUtil.readValue(key, KafkaMsgKey.class);
JsonNode jsonNode = JsonUtil.readTree(value);
long userId = msgKey.getUserId();
String roomId = msgKey.getRoomId();
String service = jsonNode.get("service").asText();
String method = jsonNode.get("method").asText();
JsonNode params = jsonNode.get("params");
int code = dispatchAllMsg(userId, roomId, service, method, params);
// 客户端要的方法返回
if (code != 0) {
ResponseVo vo = new ResponseVo(service, method, code);
MsgSender.sendMsg2Player(vo, userId);
}
} catch (Exception e) {
logger.error("mahjong 消息异常 ", e);
}
}
Aggregations