From 7d5859fa4b4d16d1554332de9bee9715bb485181 Mon Sep 17 00:00:00 2001 From: Shikong <919411476@qq.com> Date: Wed, 26 Apr 2023 13:59:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A5=E5=BF=97=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/src/main/resources/logback.xml | 53 +++++++++++++++++++ .../producer/controller/SimpleController.java | 11 ++-- 2 files changed, 58 insertions(+), 6 deletions(-) create mode 100644 common/src/main/resources/logback.xml 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()); }); } }