package com.mortals.xhx.utils.stream.service.impl;//package com.mortals.xhx.utils.stream.service.impl;
//
//import com.mortals.xhx.utils.stream.service.IMessageService;
//import lombok.extern.apachecommons.CommonsLog;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.cloud.stream.annotation.EnableBinding;
//import org.springframework.kafka.support.KafkaHeaders;
//import org.springframework.messaging.Message;
//import org.springframework.messaging.MessageChannel;
//import org.springframework.messaging.support.MessageBuilder;
//import org.springframework.stereotype.Component;
//
///**
// * @author karlhoo
// */
//@CommonsLog
//@Component
//public class DefaultMessageServiceImpl implements IMessageService {
//
//    @Override
//    public boolean sendMessage(MessageChannel messageChannel, String message) {
//        return sendMessage(messageChannel, message, null);
//    }
//
//    @Override
//    public boolean sendMessage(MessageChannel messageChannel, String message, String messageKey) {
//        return sendMessage(messageChannel, MessageBuilder.withPayload(message).setHeader(KafkaHeaders.MESSAGE_KEY, messageKey == null ? messageKey : messageKey.getBytes()).build());
//    }
//
//    private boolean sendMessage(MessageChannel messageChannel, Message message) {
//        try {
//            return messageChannel.send(message);
//        } catch (Exception e) {
//            log.error(String.format("提交消息出错 messageChannel: %s, message: %s", messageChannel.toString(), message.getPayload()), e);
//            return false;
//        }
//    }
//
//}
