package com.sckw.message.consumer;

import com.alibaba.fastjson.JSON;
import com.sckw.message.service.SckwSmsHandlerService;
import com.sckw.stream.model.SckwSms;
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: 短信消息消费
 * @author: yzc
 * @date: 2023-06-09 15:29
 */
@Configuration
@RequiredArgsConstructor
@Slf4j
public class SckwSmsConsumer {

    private final SckwSmsHandlerService sckwSmsHandlerService;

    @Bean
    public Consumer<SckwSms> sckwSms() {
        return sckwSms -> {
            try {
                sckwSmsHandlerService.handler(sckwSms);
            } catch (Exception e) {
                log.error("处理发送短信消息:{}异常", JSON.toJSONString(sckwSms), e);
            }
        };
    }

}
