模块构成
financial-common financial-base financial-core financial-gateway financial-sms financial-mq
https://lovoo.blog.csdn.net/article/details/119174146
koo-financial-parent com.koo 1.0.0 4.0.0 financial-mq 8 8 UTF-8 org.springframework.boot spring-boot-starter-amqp com.alibaba fastjson org.projectlombok lombok
@Configuration
public class MQConfig {@Beanpublic MessageConverter messageConverter(){//json字符串转换器return new Jackson2JsonMessageConverter();}
}
public class MQConst {public static final String EXCHANGE_TOPIC_SMS = "exchange.topic.sms";//交换机public static final String ROUTING_SMS_ITEM = "routing.sms.item";//路由public static final String QUEUE_SMS_ITEM = "queue.sms.item";//消息队列}
@Service
@Slf4j
public class MQService {@Resourceprivate AmqpTemplate amqpTemplate;public boolean sendMessage(String exchange, String routingKey, Object message) {log.info("发送消息。。。。。。");amqpTemplate.convertAndSend(exchange, routingKey, message);return true;}
}
com.koo financial-base 1.0.0 com.koo financial-mq 1.0.0
#spring:rabbitmq:host: 127.0.0.1port: 5672virtual-host: /financial
String mobile = userInfoService.getMobileByBindCode(bindCode);
SmsDTO smsDTO = new SmsDTO();
smsDTO.setMobile(mobile);
smsDTO.setMessage("充值成功");
mqService.sendMessage(MQConst.EXCHANGE_TOPIC_SMS,MQConst.ROUTING_SMS_ITEM,smsDTO
);
com.koo financial-mq 1.0.0
#spring:rabbitmq:host: 127.0.0.1port: 5672virtual-host: /financial
@Component
@Slf4j
public class SmsReceiver {@Resourceprivate SmsService smsService;@RabbitListener(bindings = @QueueBinding(value = @Queue(value = MQConst.QUEUE_SMS_ITEM, durable = "true"),exchange = @Exchange(value = MQConst.EXCHANGE_TOPIC_SMS),key = {MQConst.ROUTING_SMS_ITEM}))public void send(SmsDTO smsDTO) {log.info("SmsReceiver消息监听。。。。。。");HashMap param = new HashMap<>();param.put("code", smsDTO.getMessage());try {Thread.sleep(10000);} catch (InterruptedException e) {e.printStackTrace();}smsService.send(smsDTO.getMobile(), SmsProperties.TEMPLATE_CODE, param);}
}
上一篇:阿里HPCC算法简介
下一篇:HTML教程(2023-3-8)