diff --git a/common/src/main/resources/logback.xml b/common/src/main/resources/logback.xml new file mode 100644 index 0000000..7d10ddd --- /dev/null +++ b/common/src/main/resources/logback.xml @@ -0,0 +1,53 @@ + + + + + logback + + + + + + + + + + + + + %red(%d{yyyy-MM-dd HH:mm:ss.SSS}) %green([%thread]) %highlight(%-5level) %yellow(at %class.%method) (%file:%line\) - %cyan(%msg%n) + + UTF-8 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/kafka-01/kafka-01-producer/src/main/java/cn/skcks/study/springcloud/kafka/producer/controller/SimpleController.java b/kafka-01/kafka-01-producer/src/main/java/cn/skcks/study/springcloud/kafka/producer/controller/SimpleController.java index 1c81326..1b6be80 100644 --- a/kafka-01/kafka-01-producer/src/main/java/cn/skcks/study/springcloud/kafka/producer/controller/SimpleController.java +++ b/kafka-01/kafka-01-producer/src/main/java/cn/skcks/study/springcloud/kafka/producer/controller/SimpleController.java @@ -2,14 +2,14 @@ package cn.skcks.study.springcloud.kafka.producer.controller; import cn.skcks.study.springcloud.kafka.common.model.dto.Message; import cn.skcks.study.springcloud.utils.JsonUtils; -import com.fasterxml.jackson.core.JsonProcessingException; import lombok.AllArgsConstructor; -import org.springframework.beans.factory.annotation.Autowired; +import lombok.extern.slf4j.Slf4j; import org.springframework.kafka.core.KafkaTemplate; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RestController; +@Slf4j @RestController @AllArgsConstructor public class SimpleController { @@ -17,16 +17,15 @@ public class SimpleController { final static String TOPIC_NAME = "test"; @GetMapping("/api/v2/{num}") - public void sendMessage1(@PathVariable("num") String num) throws JsonProcessingException { + public void sendMessage1(@PathVariable("num") String num) { Message message = new Message(); message.setData("这是一个消息,num="+num); kafkaTemplate.send(TOPIC_NAME,num, JsonUtils.toJson(message)).addCallback(success->{ - System.out.println("发送成功"); - + log.debug("消息 {} 发送成功",message); },failure->{ - System.out.println("发送消息失败:"+failure.getMessage()); + log.info("发送消息失败 {}",failure.getMessage()); }); } }