From 06cb6aa4b94716bf39d57d5850e23faa9f3b4d8b Mon Sep 17 00:00:00 2001 From: lingniu Date: Tue, 23 Jun 2026 16:24:32 +0800 Subject: [PATCH] fix: align split app runtime dependencies --- modules/apps/gb32960-ingest-app/pom.xml | 2 +- .../src/main/resources/application.yml | 2 + .../src/main/resources/application.yml | 4 +- modules/protocols/protocol-gb32960/pom.xml | 5 +++ .../config/Gb32960AutoConfiguration.java | 6 ++- .../gb32960/config/Gb32960Properties.java | 13 ++++++- .../config/Gb32960AutoConfigurationTest.java | 37 +++++++++++++++++++ 7 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 modules/protocols/protocol-gb32960/src/test/java/com/lingniu/ingest/protocol/gb32960/config/Gb32960AutoConfigurationTest.java diff --git a/modules/apps/gb32960-ingest-app/pom.xml b/modules/apps/gb32960-ingest-app/pom.xml index 65b80f2e..d428c5fd 100644 --- a/modules/apps/gb32960-ingest-app/pom.xml +++ b/modules/apps/gb32960-ingest-app/pom.xml @@ -35,7 +35,7 @@ org.springframework.boot - spring-boot-starter + spring-boot-starter-web org.springframework.boot diff --git a/modules/apps/gb32960-ingest-app/src/main/resources/application.yml b/modules/apps/gb32960-ingest-app/src/main/resources/application.yml index 7d2e7e64..acef6c76 100644 --- a/modules/apps/gb32960-ingest-app/src/main/resources/application.yml +++ b/modules/apps/gb32960-ingest-app/src/main/resources/application.yml @@ -12,6 +12,8 @@ lingniu: ingest: gb32960: enabled: true + server: + enabled: true port: ${GB32960_PORT:32960} boss-threads: ${GB32960_BOSS_THREADS:1} worker-threads: ${GB32960_WORKER_THREADS:0} diff --git a/modules/apps/vehicle-history-app/src/main/resources/application.yml b/modules/apps/vehicle-history-app/src/main/resources/application.yml index e6f1d27c..ff706add 100644 --- a/modules/apps/vehicle-history-app/src/main/resources/application.yml +++ b/modules/apps/vehicle-history-app/src/main/resources/application.yml @@ -11,7 +11,9 @@ server: lingniu: ingest: gb32960: - enabled: false + enabled: true + server: + enabled: false sink: mq: enabled: ${KAFKA_ENABLED:true} diff --git a/modules/protocols/protocol-gb32960/pom.xml b/modules/protocols/protocol-gb32960/pom.xml index f1f523c6..9d4aa350 100644 --- a/modules/protocols/protocol-gb32960/pom.xml +++ b/modules/protocols/protocol-gb32960/pom.xml @@ -55,5 +55,10 @@ assertj-core test + + org.springframework.boot + spring-boot-test + test + diff --git a/modules/protocols/protocol-gb32960/src/main/java/com/lingniu/ingest/protocol/gb32960/config/Gb32960AutoConfiguration.java b/modules/protocols/protocol-gb32960/src/main/java/com/lingniu/ingest/protocol/gb32960/config/Gb32960AutoConfiguration.java index d1411089..2641cc54 100644 --- a/modules/protocols/protocol-gb32960/src/main/java/com/lingniu/ingest/protocol/gb32960/config/Gb32960AutoConfiguration.java +++ b/modules/protocols/protocol-gb32960/src/main/java/com/lingniu/ingest/protocol/gb32960/config/Gb32960AutoConfiguration.java @@ -59,8 +59,8 @@ import java.util.List; *

每个 Parser Bean 都会被 {@link InfoBlockParserRegistry} 按 * {@code (ProtocolVersion, typeCode)} 注册。2016/2025 可同时加载。 * - *

只有 {@code lingniu.ingest.gb32960.enabled=true} 时才会启动 32960 TCP 服务。 - * 解析、鉴权、ACK、RAW 入库都从 {@link Gb32960NettyServer} 建立的 Netty pipeline 进入。 + *

只有 {@code lingniu.ingest.gb32960.enabled=true} 时才会装配 32960 协议解析组件。 + * TCP 监听由 {@code lingniu.ingest.gb32960.server.enabled} 单独控制。 */ @AutoConfiguration @EnableConfigurationProperties(Gb32960Properties.class) @@ -222,6 +222,8 @@ public class Gb32960AutoConfiguration { @Bean @ConditionalOnMissingBean + @ConditionalOnProperty(prefix = "lingniu.ingest.gb32960.server", name = "enabled", + havingValue = "true", matchIfMissing = true) public Gb32960NettyServer gb32960NettyServer(Gb32960Properties props, Gb32960MessageDecoder decoder, Dispatcher dispatcher, diff --git a/modules/protocols/protocol-gb32960/src/main/java/com/lingniu/ingest/protocol/gb32960/config/Gb32960Properties.java b/modules/protocols/protocol-gb32960/src/main/java/com/lingniu/ingest/protocol/gb32960/config/Gb32960Properties.java index 920b5ecd..4ea74189 100644 --- a/modules/protocols/protocol-gb32960/src/main/java/com/lingniu/ingest/protocol/gb32960/config/Gb32960Properties.java +++ b/modules/protocols/protocol-gb32960/src/main/java/com/lingniu/ingest/protocol/gb32960/config/Gb32960Properties.java @@ -10,8 +10,10 @@ import java.util.Set; @ConfigurationProperties(prefix = "lingniu.ingest.gb32960") public class Gb32960Properties { - /** 是否启动 32960 TCP 监听。生产 32960 线路打开后,此开关决定端口是否真正 bind。 */ + /** 是否装配 32960 协议解析组件。TCP 监听由 {@link #server} 单独控制。 */ private boolean enabled = false; + /** 32960 TCP 监听开关。默认跟随协议启用后启动,查询类应用可单独关闭。 */ + private Server server = new Server(); /** 32960 TCP 监听端口;当前生产验证线使用 32960。 */ private int port = 9000; /** Netty worker 线程数;0 表示按 Netty/CPU 默认策略分配。 */ @@ -63,6 +65,8 @@ public class Gb32960Properties { public boolean isEnabled() { return enabled; } public void setEnabled(boolean enabled) { this.enabled = enabled; } + public Server getServer() { return server; } + public void setServer(Server server) { this.server = server; } public int getPort() { return port; } public void setPort(int port) { this.port = port; } public int getWorkerThreads() { return workerThreads; } @@ -82,6 +86,13 @@ public class Gb32960Properties { this.vendorExtensions = vendorExtensions; } + public static class Server { + private boolean enabled = true; + + public boolean isEnabled() { return enabled; } + public void setEnabled(boolean enabled) { this.enabled = enabled; } + } + /** * VIN 白名单认证。 * diff --git a/modules/protocols/protocol-gb32960/src/test/java/com/lingniu/ingest/protocol/gb32960/config/Gb32960AutoConfigurationTest.java b/modules/protocols/protocol-gb32960/src/test/java/com/lingniu/ingest/protocol/gb32960/config/Gb32960AutoConfigurationTest.java new file mode 100644 index 00000000..69bf3899 --- /dev/null +++ b/modules/protocols/protocol-gb32960/src/test/java/com/lingniu/ingest/protocol/gb32960/config/Gb32960AutoConfigurationTest.java @@ -0,0 +1,37 @@ +package com.lingniu.ingest.protocol.gb32960.config; + +import com.lingniu.ingest.core.dispatcher.Dispatcher; +import com.lingniu.ingest.protocol.gb32960.codec.Gb32960MessageDecoder; +import com.lingniu.ingest.protocol.gb32960.inbound.Gb32960NettyServer; +import org.junit.jupiter.api.Test; +import org.springframework.boot.autoconfigure.AutoConfigurations; +import org.springframework.boot.test.context.runner.ApplicationContextRunner; + +import static org.assertj.core.api.Assertions.assertThat; + +class Gb32960AutoConfigurationTest { + + private final ApplicationContextRunner runner = new ApplicationContextRunner() + .withConfiguration(AutoConfigurations.of(Gb32960AutoConfiguration.class)) + .withBean(Dispatcher.class, () -> new Dispatcher(null, null, null, null, null)) + .withPropertyValues( + "lingniu.ingest.gb32960.enabled=true", + "lingniu.ingest.gb32960.port=0"); + + @Test + void createsDecoderWithoutTcpServerWhenServerDisabled() { + runner.withPropertyValues("lingniu.ingest.gb32960.server.enabled=false") + .run(context -> { + assertThat(context).hasSingleBean(Gb32960MessageDecoder.class); + assertThat(context).doesNotHaveBean(Gb32960NettyServer.class); + }); + } + + @Test + void createsTcpServerByDefaultWhenProtocolEnabled() { + runner.run(context -> { + assertThat(context).hasSingleBean(Gb32960MessageDecoder.class); + assertThat(context).hasSingleBean(Gb32960NettyServer.class); + }); + } +}