feat(message): 添加ZT消息生产者空实现服务

- 创建 ZtMessageProducerNoOpService 类作为 Kafka 禁用时的替代实现- 实现 ConditionalOnProperty 注解,当 kafka.enabled=false 时激活该服务- 覆写 send 方法,仅记录日志而不实际发送消息
- 添加构造函数以满足父类依赖要求
- 提供详细注释说明服务用途和实现逻辑
This commit is contained in:
2025-10-14 20:28:00 +08:00
parent ad42254ea0
commit 29f4bbf2d8

View File

@@ -0,0 +1,52 @@
package com.ycwl.basic.integration.message.service;
import com.ycwl.basic.integration.message.dto.ZtMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Service;
/**
* ZT消息生产者空实现服务
* <p>
* 当 kafka.enabled=false 时,该服务会被激活,作为 ZtMessageProducerService 的替代。
* 所有消息发送操作都会被忽略,只记录日志。
* </p>
*
* @see ZtMessageProducerService
*/
@Slf4j
@Service
@ConditionalOnProperty(name = "kafka.enabled", havingValue = "false", matchIfMissing = true)
public class ZtMessageProducerNoOpService extends ZtMessageProducerService {
/**
* 空构造函数
* 由于父类需要依赖项,但在此实现中不会使用,因此传入 null
*/
public ZtMessageProducerNoOpService() {
super(null, null, null);
}
/**
* 消息发送的空操作实现
* <p>
* 当 Kafka 未启用时,此方法会被调用。
* 它不会实际发送消息,只会记录一条 debug 日志。
* </p>
*
* @param msg 待发送的消息(会被验证基本字段)
*/
@Override
public void send(ZtMessage msg) {
if (msg == null) {
log.debug("[ZT-MESSAGE] Kafka未启用,跳过消息发送(消息为null)");
return;
}
log.debug("[ZT-MESSAGE] Kafka未启用,跳过消息发送: channelId={}, title={}, target={}, messageId={}",
msg.getChannelId(),
msg.getTitle(),
msg.getTarget(),
msg.getMessageId());
}
}