当前位置: 首页 > news >正文

delphi7网站开发嘉兴市住房和城乡建设局门户网站

delphi7网站开发,嘉兴市住房和城乡建设局门户网站,docker wordpress 80,介休门户网站提示#xff1a;文章写完后#xff0c;目录可以自动生成#xff0c;如何生成可参考右边的帮助文档 文章目录 发布订阅模式 (fanout)---案例前言RabbitListener和RabbitHandler的使用 1.通过Spring官网快速创建一个RabbitMQ的生产者项目2.导入项目后在application.yml文件中配… 提示文章写完后目录可以自动生成如何生成可参考右边的帮助文档 文章目录 发布订阅模式 (fanout)---案例前言RabbitListener和RabbitHandler的使用 1.通过Spring官网快速创建一个RabbitMQ的生产者项目2.导入项目后在application.yml文件中配置3.创建一个RabbitMqConfig配置类4. 生产者5.测试生产者创建mq是否成功访问网址 http://localhost:15672/#/queues 6.再创建一个消费者项目7. 创建消费者8.测试消费者接收信息 发布订阅模式 (fanout)—案例 前言 RabbitListener和RabbitHandler的使用 1.通过Spring官网快速创建一个RabbitMQ的生产者项目 2.导入项目后在application.yml文件中配置 # 服务端口 server:port: 8081#配置rabbitmq服务 测试不用写默认本机 spring:rabbitmq:username: guest #默认账号password: guest #默认密码virtual-host: /host: localhostport: 5672#消息确认配置项#确认消息已发送到交换机 Exchangepublisher-confirm-type: correlated#确认消息已发送到队列: Queuepublisher-returns: true 3.创建一个RabbitMqConfig配置类 package com.exam.RebbitMQ.config;import org.springframework.amqp.core.Binding; import org.springframework.amqp.core.BindingBuilder; import org.springframework.amqp.core.FanoutExchange; import org.springframework.amqp.core.Queue; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration;Configuration public class RabbitMqConfig {//1:声明注册fanout模式的交换机,参数1对应的service的fanoutName参数2持久化(true,false),参数3自动删除false/trueBeanpublic FanoutExchange fanoutExchange(){return new FanoutExchange(fanout_order_exchang, true, false);}//2:声明队列 sms.fanout.queue,email.fanout.queue,duanxin.fanout.queue//参数1:名字,参数2:持久化队列true//短信队列Beanpublic Queue smsQueue() {System.err.println(执行了sms);return new Queue(sms.fanout.queue,true);}Beanpublic Queue duanxinQueue() {System.err.println(执行了duanxin);return new Queue(duanxin.fanout.queue,true);}//邮箱队列Beanpublic Queue emailQueue() {System.err.println(执行了email);return new Queue(email.fanout.queue,true);}//3:完成绑定关系(队列和交换机完成绑定关系)Beanpublic Binding smsBinding() {//把smsQueue放到fanoutExchange交换机上面return BindingBuilder.bind(smsQueue()).to(fanoutExchange());}Beanpublic Binding duanxinBinding() {//把duanxinQueue放到fanoutExchange交换机上面return BindingBuilder.bind(duanxinQueue()).to(fanoutExchange());}Beanpublic Binding emailBinding() {//把emailQueue放到fanoutExchange交换机上面return BindingBuilder.bind(emailQueue()).to(fanoutExchange());}} 4. 生产者 OrderService package com.exam.RebbitMQ.service;public interface OrderService {void makeOrder(String userid,String productid,int num); } OrderServiceImpl package com.exam.RebbitMQ.service.Impl;import java.util.UUID;import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service;import com.exam.RebbitMQ.service.OrderService;Service public class OrderServiceImpl implements OrderService{Autowiredprivate RabbitTemplate rabbitTemplate;/*** 模拟用户下单 **/public void makeOrder(String userid,String productid,int num) {//1.根据商品ID查询商品是否充足//2.保存订单String orderId UUID.randomUUID().toString();System.err.println(订单生成成功orderId);//3.通过MQ来完成消息的分发//参数1:交换机 参数二:路由key/queue队列名称 参数三:消息内容String exchangName fanout_order_exchang;String routingKey ;rabbitTemplate.convertAndSend(exchangName, routingKey, orderId);}} 5.测试生产者创建mq是否成功 在项目的test中发送请求 package com.huyi.rabbitmq;import com.huyi.rabbitmq.service.OrderService; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest;SpringBootTest class RabbitMqApplicationTests {Autowiredprivate OrderService orderService;Testvoid contextLoads() {orderService.makeOrder(1,1, 18);}} 访问网址 http://localhost:15672/#/queues 6.再创建一个消费者项目 yml配置 # 服务端口 server:port: 8082#配置rabbitmq服务 测试不用写默认本机 spring:rabbitmq:username: guest #默认账号password: guest #默认密码virtual-host: /host: localhostport: 5672#消息确认配置项#确认消息已发送到交换机 Exchangepublisher-confirm-type: correlated#确认消息已发送到队列: Queuepublisher-returns: true 7. 创建消费者 SmsConsumerService、SmsConsumerServiceImpl package com.huyi.rabbitmq_consumber.service;public interface SmsConsumerService {void reviceMessage(String message); }package com.huyi.rabbitmq_consumber.service.Impl;import com.huyi.rabbitmq_consumber.service.SmsConsumerService; import org.springframework.amqp.rabbit.annotation.RabbitHandler; import org.springframework.amqp.rabbit.annotation.RabbitListener; import org.springframework.stereotype.Component; import org.springframework.stereotype.Service;Component public class SmsConsumerServiceImpl implements SmsConsumerService {//注意这里要和生产者RabbitMqConfig文件中的名字对应起来RabbitListener(queues {sms.fanout.queue})public void reviceMessage(String message) {System.err.println(sms_fanout--接收到了订单信息);} } EmailConsumerService、EmailConsumerServiceImpl package com.huyi.rabbitmq_consumber.service;public interface EmailConsumerService {void reviceMessage(String message); } package com.huyi.rabbitmq_consumber.service.Impl;import com.huyi.rabbitmq_consumber.service.EmailConsumerService; import org.springframework.amqp.rabbit.annotation.RabbitHandler; import org.springframework.amqp.rabbit.annotation.RabbitListener; import org.springframework.stereotype.Component; import org.springframework.stereotype.Service;Component RabbitListener(queues {email.fanout.queue}) public class EmailConsumerServiceImpl implements EmailConsumerService {RabbitHandlerpublic void reviceMessage(String message) {System.err.println(Email_fanout--接收到了订单信息message);} } DuanxinConsumerService、DuanxinConsumerServiceImpl package com.huyi.rabbitmq_consumber.service;public interface DuanxinConsumerService {void reviceMessage(String message); } package com.huyi.rabbitmq_consumber.service.Impl;import com.huyi.rabbitmq_consumber.service.DuanxinConsumerService; import org.springframework.amqp.rabbit.annotation.RabbitHandler; import org.springframework.amqp.rabbit.annotation.RabbitListener; import org.springframework.stereotype.Component; import org.springframework.stereotype.Service;Component RabbitListener(queues {duanxin.fanout.queue}) public class DuanxinConsumerServiceImpl implements DuanxinConsumerService {RabbitHandlerpublic void reviceMessage(String message) {System.err.println(Duanxin_fanout--接收到了订单信息message);}} 8.测试消费者接收信息 启动消费者项目 启动生产者项目 查看消费者项目是否监听到了生产者的信息
http://www.dnsts.com.cn/news/104745.html

相关文章:

  • 安徽建设厅网站节能北备案建设网站需要提供什么资料
  • 怎么在互联网做网站wordpress ie兼容
  • 泰州市住房和城乡建设局网站深圳网站设计公司哪家工艺好
  • 网站搜索 收录优化行业网站营销特点
  • 申请一个网站需要多少钱唐山公司网站建设
  • seo站长助手眼镜 商城 网站建设
  • 九龙坡网站建设多少钱切片工具做网站怎么做
  • 夏津网站建设公司【网站建设
  • 邯郸市城乡住房建设局网站无锡网站推广优化费用
  • 如何在国外网站做推广中国企业排名
  • 鞍山市网站建设wordpress先生
  • 自己怎么设计公主房郑州百度快照优化
  • 公司网站建设建设鸿基建设工程有限公司网站
  • 青岛网站建设设计公司如何做医美机构网站观察分析
  • 网站安全软件外贸有哪些网站
  • dede 两个网站图片路径怎么做招聘有哪些网站
  • 网站建设网点重庆铜梁网站建设
  • 新网站建设ppt网站被k什么意思
  • 网站admin后台界面模板网络推广网络营销和网站推广的区别
  • 天津 网站优化邯郸网站建设信息
  • php做网站安全渗透网站做seo
  • 哪个网站做调查赚钱多前端开发培训机构推荐
  • 如何用手机建立网站wordpress主页底端添加图片
  • 西宁做腋臭北大网站Ywordpress安装完无法登录
  • yandex网站推广网站建设中企动力公司
  • 青岛高新区建设局网站wordpress视频格式
  • 广告设计接单网站四川建设厅证书查询官网
  • 做网站如何获利东莞网站建设 汇卓
  • 申请注册网站域名.商城有站点地图的网站
  • 网站制作网站开发ple id充值合肥做网站费用