diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/consumer/sms/SmsSendConsumer.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/consumer/sms/SmsSendConsumer.java index 3b4ff216b..6e039f7b0 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/consumer/sms/SmsSendConsumer.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/consumer/sms/SmsSendConsumer.java @@ -2,11 +2,11 @@ package cn.iocoder.yudao.module.system.mq.consumer.sms; import cn.iocoder.yudao.module.system.mq.message.sms.SmsSendMessage; import cn.iocoder.yudao.module.system.service.sms.SmsSendService; -import cn.iocoder.yudao.framework.mq.core.stream.AbstractStreamMessageListener; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; import javax.annotation.Resource; +import java.util.function.Consumer; /** * 针对 {@link SmsSendMessage} 的消费者 @@ -15,15 +15,14 @@ import javax.annotation.Resource; */ @Component @Slf4j -public class SmsSendConsumer extends AbstractStreamMessageListener { +public class SmsSendConsumer implements Consumer { @Resource private SmsSendService smsSendService; @Override - public void onMessage(SmsSendMessage message) { - log.info("[onMessage][消息内容({})]", message); + public void accept(SmsSendMessage message) { + log.info("[accept][消息内容({})]", message); smsSendService.doSendSms(message); } - } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/sms/SmsSendMessage.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/sms/SmsSendMessage.java index 42a32623a..e4baefcec 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/sms/SmsSendMessage.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/message/sms/SmsSendMessage.java @@ -1,9 +1,7 @@ package cn.iocoder.yudao.module.system.mq.message.sms; import cn.iocoder.yudao.framework.common.core.KeyValue; -import cn.iocoder.yudao.framework.mq.core.stream.AbstractStreamMessage; import lombok.Data; -import lombok.EqualsAndHashCode; import javax.validation.constraints.NotNull; import java.util.List; @@ -14,8 +12,7 @@ import java.util.List; * @author 芋道源码 */ @Data -@EqualsAndHashCode(callSuper = true) -public class SmsSendMessage extends AbstractStreamMessage { +public class SmsSendMessage { /** * 短信日志编号 @@ -42,9 +39,4 @@ public class SmsSendMessage extends AbstractStreamMessage { */ private List> templateParams; - @Override - public String getStreamKey() { - return "system.sms.send"; - } - } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/producer/sms/SmsProducer.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/producer/sms/SmsProducer.java index 1bcac4be3..1242e2dcb 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/producer/sms/SmsProducer.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/mq/producer/sms/SmsProducer.java @@ -1,12 +1,12 @@ package cn.iocoder.yudao.module.system.mq.producer.sms; import cn.iocoder.yudao.framework.common.core.KeyValue; -import cn.iocoder.yudao.framework.mq.core.RedisMQTemplate; import cn.iocoder.yudao.framework.mq.core.bus.AbstractBusProducer; import cn.iocoder.yudao.module.system.mq.message.sms.SmsChannelRefreshMessage; import cn.iocoder.yudao.module.system.mq.message.sms.SmsSendMessage; import cn.iocoder.yudao.module.system.mq.message.sms.SmsTemplateRefreshMessage; import lombok.extern.slf4j.Slf4j; +import org.springframework.cloud.stream.function.StreamBridge; import org.springframework.stereotype.Component; import javax.annotation.Resource; @@ -23,7 +23,7 @@ import java.util.List; public class SmsProducer extends AbstractBusProducer { @Resource - private RedisMQTemplate redisMQTemplate; + private StreamBridge streamBridge; /** * 发送 {@link SmsChannelRefreshMessage} 消息 @@ -52,7 +52,7 @@ public class SmsProducer extends AbstractBusProducer { Long channelId, String apiTemplateId, List> templateParams) { SmsSendMessage message = new SmsSendMessage().setLogId(logId).setMobile(mobile); message.setChannelId(channelId).setApiTemplateId(apiTemplateId).setTemplateParams(templateParams); - redisMQTemplate.send(message); + streamBridge.send("smsSend-out-0", message); } } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/resources/application.yaml b/yudao-module-system/yudao-module-system-biz/src/main/resources/application.yaml index 053c93d8f..1430cfd5e 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/resources/application.yaml +++ b/yudao-module-system/yudao-module-system-biz/src/main/resources/application.yaml @@ -56,15 +56,15 @@ spring: cloud: # Spring Cloud Stream 配置项,对应 BindingServiceProperties 类 stream: -# function: -# definition: roleRefreshConsumer;roleMenuRefreshConsumer;userRoleRefreshConsumer; + function: + definition: smsSendConsumer; # Binding 配置项,对应 BindingProperties Map bindings: - roleRefresh-out-0: - destination: system_role_refresh - roleRefreshConsumer-in-0: - destination: system_role_refresh - group: system_role_refresh_consumer_group + smsSend-out-0: + destination: system_sms_send + smsSendConsumer-in-0: + destination: system_sms_send + group: system_sms_send_consumer_group # Spring Cloud Stream RocketMQ 配置项 rocketmq: # RocketMQ Binder 配置项,对应 RocketMQBinderConfigurationProperties 类