system 服务:sms 短信完成 MQ 改造

This commit is contained in:
YunaiV 2022-06-21 08:23:31 +08:00
parent 9945b5fcd0
commit 4807547d73
4 changed files with 15 additions and 24 deletions

View File

@ -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<SmsSendMessage> {
public class SmsSendConsumer implements Consumer<SmsSendMessage> {
@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);
}
}

View File

@ -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<KeyValue<String, Object>> templateParams;
@Override
public String getStreamKey() {
return "system.sms.send";
}
}

View File

@ -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<KeyValue<String, Object>> 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);
}
}

View File

@ -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 类