system 服务:sms 短信完成 MQ 改造
This commit is contained in:
parent
9945b5fcd0
commit
4807547d73
@ -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.mq.message.sms.SmsSendMessage;
|
||||||
import cn.iocoder.yudao.module.system.service.sms.SmsSendService;
|
import cn.iocoder.yudao.module.system.service.sms.SmsSendService;
|
||||||
import cn.iocoder.yudao.framework.mq.core.stream.AbstractStreamMessageListener;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 针对 {@link SmsSendMessage} 的消费者
|
* 针对 {@link SmsSendMessage} 的消费者
|
||||||
@ -15,15 +15,14 @@ import javax.annotation.Resource;
|
|||||||
*/
|
*/
|
||||||
@Component
|
@Component
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class SmsSendConsumer extends AbstractStreamMessageListener<SmsSendMessage> {
|
public class SmsSendConsumer implements Consumer<SmsSendMessage> {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private SmsSendService smsSendService;
|
private SmsSendService smsSendService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onMessage(SmsSendMessage message) {
|
public void accept(SmsSendMessage message) {
|
||||||
log.info("[onMessage][消息内容({})]", message);
|
log.info("[accept][消息内容({})]", message);
|
||||||
smsSendService.doSendSms(message);
|
smsSendService.doSendSms(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
package cn.iocoder.yudao.module.system.mq.message.sms;
|
package cn.iocoder.yudao.module.system.mq.message.sms;
|
||||||
|
|
||||||
import cn.iocoder.yudao.framework.common.core.KeyValue;
|
import cn.iocoder.yudao.framework.common.core.KeyValue;
|
||||||
import cn.iocoder.yudao.framework.mq.core.stream.AbstractStreamMessage;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
|
||||||
|
|
||||||
import javax.validation.constraints.NotNull;
|
import javax.validation.constraints.NotNull;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -14,8 +12,7 @@ import java.util.List;
|
|||||||
* @author 芋道源码
|
* @author 芋道源码
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = true)
|
public class SmsSendMessage {
|
||||||
public class SmsSendMessage extends AbstractStreamMessage {
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 短信日志编号
|
* 短信日志编号
|
||||||
@ -42,9 +39,4 @@ public class SmsSendMessage extends AbstractStreamMessage {
|
|||||||
*/
|
*/
|
||||||
private List<KeyValue<String, Object>> templateParams;
|
private List<KeyValue<String, Object>> templateParams;
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getStreamKey() {
|
|
||||||
return "system.sms.send";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
package cn.iocoder.yudao.module.system.mq.producer.sms;
|
package cn.iocoder.yudao.module.system.mq.producer.sms;
|
||||||
|
|
||||||
import cn.iocoder.yudao.framework.common.core.KeyValue;
|
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.framework.mq.core.bus.AbstractBusProducer;
|
||||||
import cn.iocoder.yudao.module.system.mq.message.sms.SmsChannelRefreshMessage;
|
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.SmsSendMessage;
|
||||||
import cn.iocoder.yudao.module.system.mq.message.sms.SmsTemplateRefreshMessage;
|
import cn.iocoder.yudao.module.system.mq.message.sms.SmsTemplateRefreshMessage;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.cloud.stream.function.StreamBridge;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
@ -23,7 +23,7 @@ import java.util.List;
|
|||||||
public class SmsProducer extends AbstractBusProducer {
|
public class SmsProducer extends AbstractBusProducer {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private RedisMQTemplate redisMQTemplate;
|
private StreamBridge streamBridge;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送 {@link SmsChannelRefreshMessage} 消息
|
* 发送 {@link SmsChannelRefreshMessage} 消息
|
||||||
@ -52,7 +52,7 @@ public class SmsProducer extends AbstractBusProducer {
|
|||||||
Long channelId, String apiTemplateId, List<KeyValue<String, Object>> templateParams) {
|
Long channelId, String apiTemplateId, List<KeyValue<String, Object>> templateParams) {
|
||||||
SmsSendMessage message = new SmsSendMessage().setLogId(logId).setMobile(mobile);
|
SmsSendMessage message = new SmsSendMessage().setLogId(logId).setMobile(mobile);
|
||||||
message.setChannelId(channelId).setApiTemplateId(apiTemplateId).setTemplateParams(templateParams);
|
message.setChannelId(channelId).setApiTemplateId(apiTemplateId).setTemplateParams(templateParams);
|
||||||
redisMQTemplate.send(message);
|
streamBridge.send("smsSend-out-0", message);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -56,15 +56,15 @@ spring:
|
|||||||
cloud:
|
cloud:
|
||||||
# Spring Cloud Stream 配置项,对应 BindingServiceProperties 类
|
# Spring Cloud Stream 配置项,对应 BindingServiceProperties 类
|
||||||
stream:
|
stream:
|
||||||
# function:
|
function:
|
||||||
# definition: roleRefreshConsumer;roleMenuRefreshConsumer;userRoleRefreshConsumer;
|
definition: smsSendConsumer;
|
||||||
# Binding 配置项,对应 BindingProperties Map
|
# Binding 配置项,对应 BindingProperties Map
|
||||||
bindings:
|
bindings:
|
||||||
roleRefresh-out-0:
|
smsSend-out-0:
|
||||||
destination: system_role_refresh
|
destination: system_sms_send
|
||||||
roleRefreshConsumer-in-0:
|
smsSendConsumer-in-0:
|
||||||
destination: system_role_refresh
|
destination: system_sms_send
|
||||||
group: system_role_refresh_consumer_group
|
group: system_sms_send_consumer_group
|
||||||
# Spring Cloud Stream RocketMQ 配置项
|
# Spring Cloud Stream RocketMQ 配置项
|
||||||
rocketmq:
|
rocketmq:
|
||||||
# RocketMQ Binder 配置项,对应 RocketMQBinderConfigurationProperties 类
|
# RocketMQ Binder 配置项,对应 RocketMQBinderConfigurationProperties 类
|
||||||
|
Loading…
Reference in New Issue
Block a user