From b25c3bb686af1901eee427843756c38b41933140 Mon Sep 17 00:00:00 2001 From: Liu Wu <2780205363@qq.com> Date: Thu, 26 Sep 2024 22:03:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=A4=84=E7=90=86=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E6=96=B0=E5=A2=9E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 - .../config/MyKafkaListenerErrorHandler.java | 36 ++++++++++++ .../src/main/resources/bootstrap.yml | 56 +++++++++++++++++++ 3 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 cloud-modules/cloud-data/src/main/java/com/muyu/data/config/MyKafkaListenerErrorHandler.java create mode 100644 cloud-modules/cloud-saas/src/main/resources/bootstrap.yml diff --git a/.gitignore b/.gitignore index 872a7a6..9405b2d 100644 --- a/.gitignore +++ b/.gitignore @@ -19,7 +19,6 @@ out .project .settings .springBeans -*.yml ### IntelliJ IDEA ### .idea diff --git a/cloud-modules/cloud-data/src/main/java/com/muyu/data/config/MyKafkaListenerErrorHandler.java b/cloud-modules/cloud-data/src/main/java/com/muyu/data/config/MyKafkaListenerErrorHandler.java new file mode 100644 index 0000000..167a7fc --- /dev/null +++ b/cloud-modules/cloud-data/src/main/java/com/muyu/data/config/MyKafkaListenerErrorHandler.java @@ -0,0 +1,36 @@ +package com.muyu.data.config; + + +import lombok.NonNull; +import org.apache.kafka.clients.consumer.Consumer; +import org.springframework.kafka.annotation.KafkaListener; +import org.springframework.kafka.listener.KafkaListenerErrorHandler; +import org.springframework.kafka.listener.ListenerExecutionFailedException; +import org.springframework.kafka.support.Acknowledgment; +import org.springframework.messaging.Message; +import org.springframework.stereotype.Component; + +@Component +public class MyKafkaListenerErrorHandler implements KafkaListenerErrorHandler { + + @Override + @NonNull + public Object handleError(@NonNull Message message, + ListenerExecutionFailedException exception) { + return new Object(); + } + + @Override + @NonNull + public Object handleError(@NonNull Message message, + @NonNull ListenerExecutionFailedException exception, + Consumer consumer) { + System.out.println("消息详情:"+ message); + System.out.println("异常信息:"+ exception); + System.out.println("消费者详情:" +consumer.groupMetadata()); + System.out.println("监听主题:"+ consumer.listTopics()); + return KafkaListenerErrorHandler.super.handleError(message, exception, consumer); + } + + +} diff --git a/cloud-modules/cloud-saas/src/main/resources/bootstrap.yml b/cloud-modules/cloud-saas/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..73bf9aa --- /dev/null +++ b/cloud-modules/cloud-saas/src/main/resources/bootstrap.yml @@ -0,0 +1,56 @@ +# Tomcat +server: + port: 9523 + +# nacos线上地址 +nacos: + addr: 47.101.53.251:8848 + user-name: nacos + password: nacos + namespace: four + +# Spring +spring: + application: + # 应用名称 + name: cloud-saas + profiles: + # 环境配置 + active: dev + cloud: + nacos: + discovery: + # 服务注册地址 + server-addr: ${nacos.addr} + # nacos用户名 + username: ${nacos.user-name} + # nacos密码 + password: ${nacos.password} + # 命名空间 + namespace: ${nacos.namespace} + config: + # 服务注册地址 + server-addr: ${nacos.addr} + # nacos用户名 + username: ${nacos.user-name} + # nacos密码 + password: ${nacos.password} + # 命名空间 + namespace: ${nacos.namespace} + # 配置文件格式 + file-extension: yml + # 共享配置 + shared-configs: + # 系统共享配置 + - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} + # 系统环境Config共享配置 + - application-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} + # xxl-job 配置文件 + - application-xxl-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} + # rabbit 配置文件 + - application-rabbit-config-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension} + +logging: + level: + com.muyu.system.mapper: DEBUG +