Search in sources :

Example 16 with KafkaMsgKey

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);
}
Also used : ClubServiceMsgDispatch(com.code.server.login.service.ClubServiceMsgDispatch) KafkaMsgKey(com.code.server.constant.kafka.KafkaMsgKey) JsonNode(com.fasterxml.jackson.databind.JsonNode) KafkaListener(org.springframework.kafka.annotation.KafkaListener)

Example 17 with KafkaMsgKey

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;
}
Also used : MsgProducer(com.code.server.kafka.MsgProducer) HashMap(java.util.HashMap) KafkaMsgKey(com.code.server.constant.kafka.KafkaMsgKey) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 18 with KafkaMsgKey

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);
    });
}
Also used : KafkaMsgKey(com.code.server.constant.kafka.KafkaMsgKey) JsonNode(com.fasterxml.jackson.databind.JsonNode) UserServiceMsgDispatch(com.code.server.login.service.UserServiceMsgDispatch)

Example 19 with KafkaMsgKey

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);
    });
}
Also used : KafkaMsgKey(com.code.server.constant.kafka.KafkaMsgKey) KafkaListener(org.springframework.kafka.annotation.KafkaListener)

Example 20 with KafkaMsgKey

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);
    }
}
Also used : KafkaMsgKey(com.code.server.constant.kafka.KafkaMsgKey) JsonNode(com.fasterxml.jackson.databind.JsonNode) ResponseVo(com.code.server.constant.response.ResponseVo)

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