package com.xuexiangban.rabbitmq.springbootorderrabbitmqproducer.service;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.UUID;
/**
* @description:
* @author: xuke
* @time: 2021/3/6 0:24
*/
@Service
public class OrderService {
@Autowired
private RabbitTemplate rabbitTemplate;
/**
* @return void
* @Author xuke
* @Description 模拟用户下单
* @Date 0:25 2021/3/6
* @Param [userid, productid, num]
**/
public void makeOrder(String userid, String productid, int num) {
// 1: 根据商品id查询库存是否充足
// 2: 保存订单
String orderId = UUID.randomUUID().toString();
System.out.println("订单生产成功:" + orderId);
// 3: 通过MQ来完成消息的分发
// 参数1: 交换机 参数2:路由key/queue队列名称 参数3:消息内容
String exchangeName = "fanout_order_exchange";
String routingKey = "";
rabbitTemplate.convertAndSend(exchangeName, routingKey, orderId);
}
/**
* @return void
* @Author xuke
* @Description 模拟用户下单
* @Date 0:25 2021/3/6
* @Param [userid, productid, num]
**/
public void makeOrderDirect(String userid, String productid, int num) {
// 1: 根据商品id查询库存是否充足
// 2: 保存订单
String orderId = UUID.randomUUID().toString();
System.out.println("订单生产成功:" + orderId);
// 3: 通过MQ来完成消息的分发
// 参数1: 交换机 参数2:路由key/queue队列名称 参数3:消息内容
String exchangeName = "direct_order_exchange";
rabbitTemplate.convertAndSend(exchangeName, "email", orderId);
rabbitTemplate.convertAndSend(exchangeName, "duanxin", orderId);
}
/**
* @return void
* @Author xuke
* @Description 模拟用户下单
* @Date 0:25 2021/3/6
* @Param [userid, productid, num]
**/
public void makeOrdertopic(String userid, String productid, int num) {
// 1: 根据商品id查询库存是否充足
// 2: 保存订单
String orderId = UUID.randomUUID().toString();
System.out.println("订单生产成功:" + orderId);
// 3: 通过MQ来完成消息的分发
// 参数1: 交换机 参数2:路由key/queue队列名称 参数3:消息内容
String exchangeName = "topic_order_exchange";
String routingkey = "com.email.duanxin.test";
// #.duanxin.# duanxin
// *.email.# email
// com.# sms
rabbitTemplate.convertAndSend(exchangeName, routingkey, orderId);
}
/**
* @return void
* @Author xuke
* @Description 模拟用户下单
* @Date 0:25 2021/3/6
* @Param [userid, productid, num]
**/
public void makeOrderTtl(String userid, String productid, int num) {
// 1: 根据商品id查询库存是否充足
// 2: 保存订单
String orderId = UUID.randomUUID().toString();
System.out.println("订单生产成功:" + orderId);
// 3: 通过MQ来完成消息的分发
// 参数1: 交换机 参数2:路由key/queue队列名称 参数3:消息内容
String exchangeName = "ttl_direct_exchange";
String routingkey = "ttl";
// #.duanxin.# duanxin
// *.email.# email
// com.# sms
rabbitTemplate.convertAndSend(exchangeName, routingkey, orderId);
}
/**
* @return void
* @Author xuke
* @Description 模拟用户下单
* @Date 0:25 2021/3/6
* @Param [userid, productid, num]
**/
public void makeOrderTtlMessage(String userid, String productid, int num) {
// 1: 根据商品id查询库存是否充足
// 2: 保存订单
String orderId = UUID.randomUUID().toString();
System.out.println("订单生产成功:" + orderId);
// 3: 通过MQ来完成消息的分发
// 参数1: 交换机 参数2:路由key/queue队列名称 参数3:消息内容
String exchangeName = "ttl_direct_exchange";
String routingkey = "ttlmessage";
// 给消息设置过期时间
MessagePostProcessor messagePostProcessor = new MessagePostProcessor() {
@Override
public Message postProcessMessage(Message message) throws AmqpException {
// 这里就是字符串
message.getMessageProperties().setExpiration("5000");
message.getMessageProperties().setContentEncoding("UTF-8");
return message;
}
};
rabbitTemplate.convertAndSend(exchangeName, routingkey, orderId,messagePostProcessor);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
rabbitMQ学习笔记rabbitMQ学习笔记rabbitMQ学习笔记rabbitMQ学习笔记rabbitMQ学习笔记rabbitMQ学习笔记rabbitMQ学习笔记rabbitMQ学习笔记rabbitMQ学习笔记rabbitMQ学习笔记rabbitMQ学习笔记rabbitMQ学习笔记rabbitMQ学习笔记rabbitMQ学习笔记rabbitMQ学习笔记rabbitMQ学习笔记rabbitMQ学习笔记rabbitMQ学习笔记rabbitMQ学习笔记rabbitMQ学习笔记rabbitMQ学习笔记rabbitMQ学习笔记rabbitMQ学习笔记rabbitMQ学习笔记rabbitMQ学习笔记rabbitMQ学习笔记rabbitMQ学习笔记rabbitMQ学习笔记rabbitMQ学习笔记rabbitMQ学习笔记rabbitMQ学习笔记rabbitMQ学习笔记rabbitMQ学习笔记rabbitMQ学习笔记rabbitMQ学习笔记rabbitMQ学习笔记rabbitMQ学习笔记rabbitMQ学习笔记rabbitMQ学习笔记rabbitMQ学习笔记rabbitMQ学习笔记
资源推荐
资源详情
资源评论
收起资源包目录
rabbitMQ学习笔记 (711个子文件)
JsonUtil.class 5KB
JsonUtil.class 5KB
RabbitMqConfiguration2.class 3KB
Producer.class 3KB
OrderService.class 3KB
OrderService.class 3KB
Consumer$1.class 3KB
Consumer$1.class 3KB
TTLRabbitMqConfiguration.class 3KB
RabbitMqConfiguration.class 3KB
Work1.class 3KB
Producer.class 3KB
Producer.class 3KB
Producer.class 3KB
Work2.class 2KB
Producer.class 2KB
Work2.class 2KB
Work1.class 2KB
DirectRabbitMqConfiguration.class 2KB
DirectRabbitMqConfiguration.class 2KB
Consumer.class 2KB
OrderService.class 2KB
OrderMqConsumer.class 2KB
RabbitMqConfiguration.class 2KB
RabbitMqConfiguration2.class 2KB
DeadMqConsumer.class 2KB
RabbitMqConfiguration.class 2KB
OrderMQService$1.class 2KB
TTLRabbitMqConfiguration.class 2KB
RabbitMQConfiguration.class 2KB
OrderMQService.class 2KB
RabbitMqConfiguration.class 2KB
OrderDataBaseService.class 2KB
KuangstudyOrderServiceApplicationTests.class 2KB
DeadRabbitMqConfiguration.class 2KB
RabbitMqConfiguration.class 2KB
Order.class 2KB
Order.class 2KB
OrderService.class 2KB
OrderService.class 2KB
OrderService.class 2KB
Consumer$1.class 2KB
SpringbootOrderRabbitmqProducerApplicationTests.class 2KB
WeixinConsumerService.class 2KB
EmailConsumerService.class 2KB
SMSConsumerService.class 2KB
DispatchService.class 2KB
OrderController.class 2KB
SpringbootRabbitmqFanoutProducerApplicationTests.class 1KB
SpringbootRabbitmqDirectProducerApplicationTests.class 1KB
TopicDuanxinConsumer.class 1KB
TestController.class 1KB
TopicEmailConsumer.class 1KB
OrderService$1.class 1KB
OrderService$1.class 1KB
SpringbootRabbitmqTopicProducerApplicationTests.class 1KB
TopicDuanxinConsumber.class 1KB
TopicSMSConsumer.class 1KB
TopicEmailConsumber.class 1KB
TopicSmsConsumber.class 1KB
Work1$1.class 1KB
SpringbootOrderRabbitmqProducerApplicationTests.class 1KB
Consumer$1$1.class 1KB
Work2$1.class 1KB
Work1$1.class 1KB
Work2$1.class 1KB
Consumer$1$1.class 1KB
DuanxinConsumerService.class 1KB
WeixinConsumerService.class 1KB
DuanxinConsumerService.class 1KB
EmailConsumerService.class 1KB
WeixinConsumerService.class 1KB
EmailConsumerService.class 1KB
SMSConsumerService.class 1KB
SMSConsumerService.class 1KB
DispatchController.class 1KB
FanoutDuanxinConsumer.class 1KB
DirectDuanxinConsumer.class 1KB
DirectEmailConsumer.class 1KB
FanoutEmailConsumer.class 1KB
DirectDuanxinConsumber.class 1KB
MessageConfirmCallback.class 1KB
FanoutSMSConsumer.class 1KB
DirectSMSConsumer.class 1KB
DirectEmailConsumber.class 1KB
DirectSmsConsumber.class 1KB
DuanxinConsumber.class 1KB
EmailConsumber.class 1KB
SmsConsumber.class 1KB
MQOrderService.class 1KB
SpringbootOrderRabbitmqConsumberApplication.class 899B
SpringbootRabbitmqFanoutProducerApplication.class 899B
SpringbootRabbitmqDirectConsumerApplication.class 899B
SpringbootRabbitmqFanoutConsumerApplication.class 899B
SpringbootRabbitmqFanoutProducerApplication.class 899B
SpringbootRabbitmqDirectProducerApplication.class 899B
SpringbootRabbitmqFanoutConsumerApplication.class 899B
SpringbootOrderRabbitmqProducerApplication.class 894B
SpringbootRabbitmqTopicConsumerApplication.class 894B
SpringbootOrderRabbitmqConsumerApplication.class 894B
共 711 条
- 1
- 2
- 3
- 4
- 5
- 6
- 8
资源评论
带上耳机世界与我无关
- 粉丝: 1164
- 资源: 10
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- (源码)基于C语言的系统服务框架.zip
- (源码)基于Spring MVC和MyBatis的选课管理系统.zip
- (源码)基于ArcEngine的GIS数据处理系统.zip
- (源码)基于JavaFX和MySQL的医院挂号管理系统.zip
- (源码)基于IdentityServer4和Finbuckle.MultiTenant的多租户身份认证系统.zip
- (源码)基于Spring Boot和Vue3+ElementPlus的后台管理系统.zip
- (源码)基于C++和Qt框架的dearoot配置管理系统.zip
- (源码)基于 .NET 和 EasyHook 的虚拟文件系统.zip
- (源码)基于Python的金融文档智能分析系统.zip
- (源码)基于Java的医药管理系统.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功