fix(mq-starter-core): 单条监听器显式 batchTimeoutMs=0/负数不再误报 WARN

review 发现 #2:软校验只判 != 60_000,而注解文档明确"0 或负数 = 关闭超时
刷出"。单条监听器显式写 0 语义无害,却触发"配置不生效"WARN 误导运维。

修复:WARN 条件补 batchTimeoutMs > 0,显式关闭(0/负数)不再告警。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-15 02:57:32 +01:00
parent 0e8e3762d2
commit b735c95879
2 changed files with 21 additions and 2 deletions

View File

@@ -47,8 +47,9 @@ public class MqListenerAnnotationBeanPostProcessor implements BeanPostProcessor
} else if (batch && meta.batchSize() <= 1) {
log.warn("[mq] @MqListener 首参为 List 但 batchSize={},将按 1 条一批回调(如需攒批请设置 batchSize>1: {}", meta.batchSize(), m);
}
// batchTimeoutMs 仅批量攒批时有意义;已知局限:显式写 60000恰为缺省值检测不出可接受
if (meta.batchSize() <= 1 && meta.batchTimeoutMs() != 60_000) {
// batchTimeoutMs 仅批量攒批时有意义;0/负数 = 显式关闭超时,任何监听器上都无害不告警
// 已知局限:显式写 60000(恰为缺省值)检测不出,可接受。
if (meta.batchSize() <= 1 && meta.batchTimeoutMs() != 60_000 && meta.batchTimeoutMs() > 0) {
log.warn("[mq] @MqListener batchTimeoutMs={} 仅对批量监听器batchSize>1生效当前 batchSize={} 下不生效: {}",
meta.batchTimeoutMs(), meta.batchSize(), m);
}

View File

@@ -127,4 +127,22 @@ class MqListenerScanTest {
bpp.postProcessAfterInitialization(new BatchWithCustomTimeout(), "biz");
assertEquals(0, warnCount(), "批量监听器配 batchTimeoutMs 属正常用法,不应 WARN");
}
static class TimeoutOffZeroOnSingle {
@MqListener(topic = "W5", group = "wg5", batchTimeoutMs = 0)
public void onOne(String msg) { }
}
static class TimeoutOffNegativeOnSingle {
@MqListener(topic = "W6", group = "wg6", batchTimeoutMs = -1)
public void onOne(String msg) { }
}
@Test
void scan_batchTimeoutOffOnSingleListener_noWarn() {
MqListenerAnnotationBeanPostProcessor bpp = new MqListenerAnnotationBeanPostProcessor();
bpp.postProcessAfterInitialization(new TimeoutOffZeroOnSingle(), "biz1");
bpp.postProcessAfterInitialization(new TimeoutOffNegativeOnSingle(), "biz2");
assertEquals(0, warnCount(), "0/负数 = 关闭超时,单条监听器显式关闭语义无害,不应误报 WARN");
}
}