package com.sckw.message.consumer;

import com.alibaba.fastjson.JSON;
import com.sckw.message.service.SckwMessageHandlerService;
import com.sckw.stream.model.SckwMessage;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.function.Consumer;

/**
 * @desc: message消费相关
 * @author: yzc
 * @date: 2023-06-09 15:32
 */
@Configuration
@RequiredArgsConstructor
@Slf4j
public class SckwMessageConsumer {
    private final SckwMessageHandlerService sckwMessageHandlerService;

    @Bean
    public Consumer<SckwMessage> sckwMessage() {
        return sckwMessage -> {
            try {
                sckwMessageHandlerService.handler(sckwMessage);
            } catch (Exception e) {
                log.error("处理message消息:{}异常", JSON.toJSONString(sckwMessage), e);
            }
        };
    }
}
