Search in sources :

Example 1 with UserServiceMsgDispatch

use of com.code.server.login.service.UserServiceMsgDispatch 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)

Example 2 with UserServiceMsgDispatch

use of com.code.server.login.service.UserServiceMsgDispatch 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)

Aggregations

KafkaMsgKey (com.code.server.constant.kafka.KafkaMsgKey)2 UserServiceMsgDispatch (com.code.server.login.service.UserServiceMsgDispatch)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 KafkaListener (org.springframework.kafka.annotation.KafkaListener)1