Search in sources :

Example 11 with KafkaMsgKey

use of com.code.server.constant.kafka.KafkaMsgKey in project summer by foxsugar.

the class Room method clubRoomSetId.

/**
 * 俱乐部 设置id
 */
public void clubRoomSetId() {
    if (isClubRoom()) {
        MsgProducer msgProducer = SpringUtil.getBean(MsgProducer.class);
        KafkaMsgKey kafkaKey = new KafkaMsgKey();
        kafkaKey.setUserId(0);
        Map<String, String> msg = new HashMap<>();
        msg.put("clubId", this.clubId);
        msg.put("clubModelId", this.clubRoomModel);
        msg.put("roomId", this.roomId);
        ResponseVo responseVo = new ResponseVo("clubService", "clubRoomSetId", msg);
        msgProducer.send("clubService", kafkaKey, responseVo);
    }
}
Also used : MsgProducer(com.code.server.kafka.MsgProducer) KafkaMsgKey(com.code.server.constant.kafka.KafkaMsgKey)

Example 12 with KafkaMsgKey

use of com.code.server.constant.kafka.KafkaMsgKey in project summer by foxsugar.

the class Server2ServerMsgDispatch method dispatch.

public static void dispatch(ConsumerRecord<String, String> record) {
    KafkaMsgKey msgKey = JsonUtil.readValue(record.key(), KafkaMsgKey.class);
    JsonNode params = JsonUtil.readTree(record.value());
    // String service = params.get("service").asText();
    String method = params.get("method").asText();
    JsonNode node = params.get("params");
    switch(method) {
        case "kickUser":
            kickUser(msgKey, node.path("roomId").asText(), node.path("kickUser").asLong());
            break;
        case "getRoomInfo":
            getRoomInfo(msgKey, node.path("roomId").asText());
            break;
    }
}
Also used : KafkaMsgKey(com.code.server.constant.kafka.KafkaMsgKey) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 13 with KafkaMsgKey

use of com.code.server.constant.kafka.KafkaMsgKey in project summer by foxsugar.

the class GameClubService method sendMsgForCreateRoom.

/**
 * 向逻辑服务器 发送创建的内部消息
 *
 * @param serviceName
 * @param createCommand
 */
private static void sendMsgForCreateRoom(String serviceName, String createCommand) {
    MsgProducer msgProducer = SpringUtil.getBean(MsgProducer.class);
    int serverId = getServerIdByServiceName(serviceName);
    KafkaMsgKey msgKey = new KafkaMsgKey();
    msgKey.setUserId(0);
    msgProducer.send2Partition(serviceName, serverId, JsonUtil.toJson(msgKey), createCommand);
}
Also used : MsgProducer(com.code.server.kafka.MsgProducer) KafkaMsgKey(com.code.server.constant.kafka.KafkaMsgKey)

Example 14 with KafkaMsgKey

use of com.code.server.constant.kafka.KafkaMsgKey in project summer by foxsugar.

the class GameInfo method genRecord.

@Override
protected void genRecord() {
    long id = IdWorker.getDefaultInstance().nextId();
    genRecord(playerCardsInfos.values().stream().collect(Collectors.toMap(PlayerCardsInfoMj::getUserId, PlayerCardsInfoMj::getScore)), room, id);
    replay.setId(id);
    replay.setCount(playerCardsInfos.size());
    replay.setRoom_uuid(this.room.getUuid());
    replay.setRoomInfo(this.getRoom().toJSONObject());
    KafkaMsgKey kafkaMsgKey = new KafkaMsgKey().setMsgId(KAFKA_MSG_ID_REPLAY);
    MsgProducer msgProducer = SpringUtil.getBean(MsgProducer.class);
    msgProducer.send(IKafaTopic.CENTER_TOPIC, kafkaMsgKey, replay);
}
Also used : MsgProducer(com.code.server.kafka.MsgProducer) KafkaMsgKey(com.code.server.constant.kafka.KafkaMsgKey)

Example 15 with KafkaMsgKey

use of com.code.server.constant.kafka.KafkaMsgKey in project summer by foxsugar.

the class UserServiceMsgConsumer method listen.

@KafkaListener(id = "userService", topicPattern = "userService")
public void listen(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);
    });
}
Also used : KafkaMsgKey(com.code.server.constant.kafka.KafkaMsgKey) JsonNode(com.fasterxml.jackson.databind.JsonNode) UserServiceMsgDispatch(com.code.server.login.service.UserServiceMsgDispatch) KafkaListener(org.springframework.kafka.annotation.KafkaListener)

Aggregations

KafkaMsgKey (com.code.server.constant.kafka.KafkaMsgKey)32 MsgProducer (com.code.server.kafka.MsgProducer)25 HashMap (java.util.HashMap)14 ServerConfig (com.code.server.game.poker.config.ServerConfig)11 ResponseRobotVo (com.code.server.game.poker.robot.ResponseRobotVo)11 JsonNode (com.fasterxml.jackson.databind.JsonNode)6 KafkaListener (org.springframework.kafka.annotation.KafkaListener)3 UserBean (com.code.server.constant.game.UserBean)2 UserRecord (com.code.server.constant.game.UserRecord)2 ResponseVo (com.code.server.constant.response.ResponseVo)2 UserServiceMsgDispatch (com.code.server.login.service.UserServiceMsgDispatch)2 CardStruct (com.code.server.constant.game.CardStruct)1 GameRecord (com.code.server.constant.game.GameRecord)1 RoomRecord (com.code.server.constant.game.RoomRecord)1 ClubServiceMsgDispatch (com.code.server.login.service.ClubServiceMsgDispatch)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1