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

揭阳市网站建设_网站建设公司_导航菜单_seo优化

山东地产网站建设,国外军事新闻最新消息,网站排版怎么做,太原网站建设网格未来文章目录一.搭建SpringBoot环境二.配置1.配置application.yml2.定义RabbitConfig类三.生产端四.消费端一.搭建SpringBoot环境 我们选择基于Spring-Rabbit去操作RabbitMQ 使用spring-boot-starter-amqp会自动添加spring-rabbit依赖#xff0c;如下#xff1a; dependenc… 文章目录一.搭建SpringBoot环境二.配置1.配置application.yml2.定义RabbitConfig类三.生产端四.消费端一.搭建SpringBoot环境 我们选择基于Spring-Rabbit去操作RabbitMQ 使用spring-boot-starter-amqp会自动添加spring-rabbit依赖如下 dependencygroupIdorg.springframework.boot/groupIdartifactIdspring‐boot‐starter‐amqp/artifactId /dependency dependencygroupIdorg.springframework.boot/groupIdartifactIdspring‐boot‐starter‐test/artifactId /dependency dependencygroupIdorg.springframework.boot/groupIdartifactIdspring‐boot‐starter‐logging/artifactId /dependency二.配置 1.配置application.yml 配置连接rabbitmq的参数 server:port: 44000 spring:application:name: test-rabbitmq-producerrabbitmq:host: 127.0.0.1port: 5672username: guestpassword: guestvirtualHost: /2.定义RabbitConfig类 定义RabbitConfig类配置Exchange、Queue、及绑定交换机 本例配置Topic交换机 package com.xuecheng.test.rabbitmq.config;import org.springframework.amqp.core.*; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration;Configuration public class RabbitmqConfig {public static final String QUEUE_INFORM_EMAIL queue_inform_email;public static final String QUEUE_INFORM_SMS queue_inform_sms;public static final String EXCHANGE_TOPICS_INFORMexchange_topics_inform;public static final String ROUTINGKEY_EMAILinform.#.email.#;public static final String ROUTINGKEY_SMSinform.#.sms.#;//声明交换机Bean(EXCHANGE_TOPICS_INFORM)public Exchange EXCHANGE_TOPICS_INFORM(){//durable(true) 持久化mq重启之后交换机还在return ExchangeBuilder.topicExchange(EXCHANGE_TOPICS_INFORM).durable(true).build();}//声明QUEUE_INFORM_EMAIL队列Bean(QUEUE_INFORM_EMAIL)public Queue QUEUE_INFORM_EMAIL(){return new Queue(QUEUE_INFORM_EMAIL);}//声明QUEUE_INFORM_SMS队列Bean(QUEUE_INFORM_SMS)public Queue QUEUE_INFORM_SMS(){return new Queue(QUEUE_INFORM_SMS);}//ROUTINGKEY_EMAIL队列绑定交换机指定routingKeyBeanpublic Binding BINDING_QUEUE_INFORM_EMAIL(Qualifier(QUEUE_INFORM_EMAIL) Queue queue,Qualifier(EXCHANGE_TOPICS_INFORM) Exchange exchange){return BindingBuilder.bind(queue).to(exchange).with(ROUTINGKEY_EMAIL).noargs();}//ROUTINGKEY_SMS队列绑定交换机指定routingKeyBeanpublic Binding BINDING_ROUTINGKEY_SMS(Qualifier(QUEUE_INFORM_SMS) Queue queue,Qualifier(EXCHANGE_TOPICS_INFORM) Exchange exchange){return BindingBuilder.bind(queue).to(exchange).with(ROUTINGKEY_SMS).noargs();}} 三.生产端 使用RarbbitTemplate发送消息 package com.xuecheng.test.rabbitmq; import com.xuecheng.test.rabbitmq.config.RabbitmqConfig; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; SpringBootTest RunWith(SpringRunner.class) public class Producer05_topics_springboot { Autowired RabbitTemplate rabbitTemplate; Test public void testSendByTopics(){ for (int i0;i5;i){ String message sms email inform to useri; rabbitTemplate.convertAndSend(RabbitmqConfig.EXCHANGE_TOPICS_INFORM,inform.sms.email,message); System.out.println(Send Message is: message ); } } }四.消费端 创建消费端工程添加依赖 dependencygroupIdorg.springframework.boot/groupIdartifactIdspring‐boot‐starter‐amqp/artifactId /dependency dependencygroupIdorg.springframework.boot/groupIdartifactIdspring‐boot‐starter‐test/artifactId /dependency dependencygroupIdorg.springframework.boot/groupIdartifactIdspring‐boot‐starter‐logging/artifactId /dependency使用RabbitListener注解监听队列 package com.xuecheng.test.rabbitmq.mq; import com.rabbitmq.client.Channel; import com.xuecheng.test.rabbitmq.config.RabbitmqConfig; import org.springframework.amqp.core.Message; import org.springframework.amqp.rabbit.annotation.RabbitListener; import org.springframework.stereotype.Component; Component public class ReceiveHandler { //监听email队列 RabbitListener(queues {RabbitmqConfig.QUEUE_INFORM_EMAIL}) public void receive_email(String msg,Message message,Channel channel){ System.out.println(msg); } / /监听sms队列 RabbitListener(queues {RabbitmqConfig.QUEUE_INFORM_SMS}) public void receive_sms(String msg,Message message,Channel channel){ System.out.println(msg); } }
http://www.ihoyoo.com/news/49751.html

相关文章:

  • 合肥网站设计goz汕头微网站
  • 贵阳网站优化排名怎样做好手机网站建设
  • wordpress 支付接口长沙网站seo服务
  • 湖南长沙网站建设公司准备网站的工作
  • 网站建设简单合同模板下载wordpress上传第二部
  • 权大师的网站是哪个公司做的网站开发 英文文章
  • 阿里云无主体新增网站烟台专业做网站的公司
  • 什么是商业网站肥西县城乡建设局网站
  • 网站 邮箱功能 设置网站推广途径方法
  • 资溪做面包招聘的网站闸北网站优化公司
  • 邯郸手机网站建设南京网站定制南京
  • 建设工程协会网站西地那非多少钱一盒
  • 自己怎么做彩票网站郑州制作网站ihanshi
  • 郴州市建设局网站节能科黄骅市网站建设公司
  • 建设项目备案网站开网站做代销好
  • 太原营销网站建设制作平台网站定制电话
  • 做网站卖什么青岛建站模板厂家
  • 网站开发的流行架构学网页设计怎么样
  • 铜陵港航投资建设集团网站seo关键词排名优化专业公司
  • wordpress 建视频网站吗免费做网站的好不好
  • .net asp可以外链其它网站吗阿里巴巴国际网站官网入口
  • 自助建站的一般流程做网站一年百万
  • 焦作网站seo网店设计是做什么的
  • 门户网站架构建设h5网站
  • 深圳 购物网站wordpress 去除邮箱
  • 建筑网络工程教程深圳企业股权优化
  • 深圳互助资金盘网站开发网站基本建设
  • 北京网站维护公司装饰工程公司排名
  • 网站开发风险oa信息管理系统
  • 三维立体网站建设乐清问政网络平台