From bde042120ba905548fc2056c3d393750c538a1d6 Mon Sep 17 00:00:00 2001 From: willisyan Date: Tue, 2 Sep 2025 21:10:58 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dspringboot=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E9=98=B6=E6=AE=B5=E5=BC=82=E5=B8=B8=E6=97=B6=E4=BC=9A?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E8=BF=9B=E7=A8=8B=E5=81=87=E6=AD=BB=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TRpcApplicationFailedListener.java | 38 +++++++++++++++++++ .../main/resources/META-INF/spring.factories | 3 +- 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 trpc-spring-boot-starters/trpc-spring-boot-starter/src/main/java/com/tencent/trpc/spring/boot/starters/listener/TRpcApplicationFailedListener.java diff --git a/trpc-spring-boot-starters/trpc-spring-boot-starter/src/main/java/com/tencent/trpc/spring/boot/starters/listener/TRpcApplicationFailedListener.java b/trpc-spring-boot-starters/trpc-spring-boot-starter/src/main/java/com/tencent/trpc/spring/boot/starters/listener/TRpcApplicationFailedListener.java new file mode 100644 index 0000000000..4e99044fbf --- /dev/null +++ b/trpc-spring-boot-starters/trpc-spring-boot-starter/src/main/java/com/tencent/trpc/spring/boot/starters/listener/TRpcApplicationFailedListener.java @@ -0,0 +1,38 @@ +/* + * Tencent is pleased to support the open source community by making tRPC available. + * + * Copyright (C) 2023 Tencent. + * All rights reserved. + * + * If you have downloaded a copy of the tRPC source code from Tencent, + * please note that tRPC source code is licensed under the Apache 2.0 License, + * A copy of the Apache 2.0 License can be found in the LICENSE file. + */ + +package com.tencent.trpc.spring.boot.starters.listener; + +import com.tencent.trpc.core.common.ConfigManager; +import org.springframework.boot.context.event.ApplicationFailedEvent; +import org.springframework.context.ApplicationListener; +import org.springframework.core.annotation.Order; + +import java.util.concurrent.atomic.AtomicBoolean; + +/** + * Handle the application failed event, the reason is TRpcLifecycleManager is called before the application failed. + */ +@Order +public class TRpcApplicationFailedListener implements ApplicationListener { + private static final AtomicBoolean PROCESSED = new AtomicBoolean(false); + + @Override + public void onApplicationEvent(ApplicationFailedEvent event) { + if (PROCESSED.compareAndSet(false, true)) { + stopTRPC(); + } + } + + private void stopTRPC() { + ConfigManager.getInstance().stop(); + } +} \ No newline at end of file diff --git a/trpc-spring-boot-starters/trpc-spring-boot-starter/src/main/resources/META-INF/spring.factories b/trpc-spring-boot-starters/trpc-spring-boot-starter/src/main/resources/META-INF/spring.factories index 7dfeda0fd4..0df8d0be85 100644 --- a/trpc-spring-boot-starters/trpc-spring-boot-starter/src/main/resources/META-INF/spring.factories +++ b/trpc-spring-boot-starters/trpc-spring-boot-starter/src/main/resources/META-INF/spring.factories @@ -1,5 +1,6 @@ org.springframework.context.ApplicationListener=\ - com.tencent.trpc.spring.boot.starters.listener.TRpcBannerListener + com.tencent.trpc.spring.boot.starters.listener.TRpcBannerListener,\ + com.tencent.trpc.spring.boot.starters.listener.TRpcApplicationFailedListener org.springframework.boot.env.EnvironmentPostProcessor=\ com.tencent.trpc.spring.boot.starters.env.TRpcConfigurationEnvironmentPostProcessor org.springframework.context.ApplicationContextInitializer=\ From d402e607d08de3723d25c2f9449eee0e3154cdfd Mon Sep 17 00:00:00 2001 From: willisyan Date: Mon, 8 Sep 2025 18:03:47 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E9=87=8D=E6=96=B0=E5=87=BA=E5=8F=91workflo?= =?UTF-8?q?w?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../boot/starters/listener/TRpcApplicationFailedListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trpc-spring-boot-starters/trpc-spring-boot-starter/src/main/java/com/tencent/trpc/spring/boot/starters/listener/TRpcApplicationFailedListener.java b/trpc-spring-boot-starters/trpc-spring-boot-starter/src/main/java/com/tencent/trpc/spring/boot/starters/listener/TRpcApplicationFailedListener.java index 4e99044fbf..c6ceb55ea9 100644 --- a/trpc-spring-boot-starters/trpc-spring-boot-starter/src/main/java/com/tencent/trpc/spring/boot/starters/listener/TRpcApplicationFailedListener.java +++ b/trpc-spring-boot-starters/trpc-spring-boot-starter/src/main/java/com/tencent/trpc/spring/boot/starters/listener/TRpcApplicationFailedListener.java @@ -19,7 +19,7 @@ import java.util.concurrent.atomic.AtomicBoolean; /** - * Handle the application failed event, the reason is TRpcLifecycleManager is called before the application failed. + * Handle the application failed event, the reason is TRpcLifecycleManager called before the application failed. */ @Order public class TRpcApplicationFailedListener implements ApplicationListener { From 51b8591f844a2d699c50e7f6679808ce6d9f5e09 Mon Sep 17 00:00:00 2001 From: yzhfd Date: Mon, 8 Sep 2025 20:45:42 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E9=87=8D=E6=96=B0=E5=87=BA=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../trpc/proto/standard/concurrenttest/TcpConcurrentTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trpc-proto/trpc-proto-standard/src/test/java/com/tencent/trpc/proto/standard/concurrenttest/TcpConcurrentTest.java b/trpc-proto/trpc-proto-standard/src/test/java/com/tencent/trpc/proto/standard/concurrenttest/TcpConcurrentTest.java index 25a33ba07c..15c5f0f7ed 100644 --- a/trpc-proto/trpc-proto-standard/src/test/java/com/tencent/trpc/proto/standard/concurrenttest/TcpConcurrentTest.java +++ b/trpc-proto/trpc-proto-standard/src/test/java/com/tencent/trpc/proto/standard/concurrenttest/TcpConcurrentTest.java @@ -32,7 +32,7 @@ public class TcpConcurrentTest { - private static final int TCP_PORT = 12321; + private static final int TCP_PORT = 12421; ProviderConfig providerConfig; ServiceConfig serviceConfig; From 9a2e8310563f8078d4738b0313c5818bed0c6c32 Mon Sep 17 00:00:00 2001 From: "yanzhenfd@163.com" Date: Mon, 8 Sep 2025 20:49:13 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E9=87=8D=E6=96=B0=E5=87=BA=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../boot/starters/listener/TRpcApplicationFailedListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trpc-spring-boot-starters/trpc-spring-boot-starter/src/main/java/com/tencent/trpc/spring/boot/starters/listener/TRpcApplicationFailedListener.java b/trpc-spring-boot-starters/trpc-spring-boot-starter/src/main/java/com/tencent/trpc/spring/boot/starters/listener/TRpcApplicationFailedListener.java index c6ceb55ea9..7b47c1c5e2 100644 --- a/trpc-spring-boot-starters/trpc-spring-boot-starter/src/main/java/com/tencent/trpc/spring/boot/starters/listener/TRpcApplicationFailedListener.java +++ b/trpc-spring-boot-starters/trpc-spring-boot-starter/src/main/java/com/tencent/trpc/spring/boot/starters/listener/TRpcApplicationFailedListener.java @@ -19,7 +19,7 @@ import java.util.concurrent.atomic.AtomicBoolean; /** - * Handle the application failed event, the reason is TRpcLifecycleManager called before the application failed. + * Handle the application failed event, the reason was TRpcLifecycleManager called before the application failed. */ @Order public class TRpcApplicationFailedListener implements ApplicationListener { From b89cd114acbab424d9ea463ccd90e0b7f95d3c28 Mon Sep 17 00:00:00 2001 From: yzhfd Date: Mon, 8 Sep 2025 21:06:07 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E9=87=8D=E6=96=B0=E5=87=BA=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../boot/starters/listener/TRpcApplicationFailedListener.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/trpc-spring-boot-starters/trpc-spring-boot-starter/src/main/java/com/tencent/trpc/spring/boot/starters/listener/TRpcApplicationFailedListener.java b/trpc-spring-boot-starters/trpc-spring-boot-starter/src/main/java/com/tencent/trpc/spring/boot/starters/listener/TRpcApplicationFailedListener.java index 7b47c1c5e2..c6ceb55ea9 100644 --- a/trpc-spring-boot-starters/trpc-spring-boot-starter/src/main/java/com/tencent/trpc/spring/boot/starters/listener/TRpcApplicationFailedListener.java +++ b/trpc-spring-boot-starters/trpc-spring-boot-starter/src/main/java/com/tencent/trpc/spring/boot/starters/listener/TRpcApplicationFailedListener.java @@ -19,7 +19,7 @@ import java.util.concurrent.atomic.AtomicBoolean; /** - * Handle the application failed event, the reason was TRpcLifecycleManager called before the application failed. + * Handle the application failed event, the reason is TRpcLifecycleManager called before the application failed. */ @Order public class TRpcApplicationFailedListener implements ApplicationListener {