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

淮北网站开发公司移动排名提升软件

淮北网站开发公司,移动排名提升软件,二手商品交易网站开发,网站建设和网页设计是不是一样一、简介 在Spring项目中#xff0c;可以使用Spring-Rabbit去操作RabbitMQ 尤其是在spring boot项目中只需要引入对应的amqp启动器依赖即可#xff0c;方便的使用RabbitTemplate发送消息#xff0c;使用注解接收消息。 一般在开发过程中#xff1a; 生产者工程#xf…一、简介 在Spring项目中可以使用Spring-Rabbit去操作RabbitMQ 尤其是在spring boot项目中只需要引入对应的amqp启动器依赖即可方便的使用RabbitTemplate发送消息使用注解接收消息。 一般在开发过程中 生产者工程 application.yml文件配置相关信息在生产者工程中编写配置类用于创建交换机和队列并进行绑定注入RabbitTemplate对象通过RabbitTemplate对象发送消息到交换机 消费者工程 application.yml文件配置相关信息创建消息处理类用于接收队列中的消息并进行处理 二、项目结构 三、加入依赖jar dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-amqp/artifactId /dependency 四、编写配置文件 spring:rabbitmq:username: userpassword: 123456virtual-host: /adminport: 5672 mq:exchange:name: test_exchange_topicqueue:name1: test_topic_exchange_queue1name2: test_topic_exchange_queue2 五、编写配置类 import org.springframework.amqp.core.*; import org.springframework.amqp.core.ExchangeBuilder; import org.springframework.amqp.core.QueueBuilder; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration;Configuration public class TopicConfig {Value(${mq.exchange.name})private String EXCHANGENAME;Value(${mq.queue.name1})private String QUEUENAME1;Value(${mq.queue.name2})private String QUEUENAME2;Bean(Exchange)public Exchange getExchange(){Exchange exchange ExchangeBuilder.topicExchange(EXCHANGENAME).durable(false).build();return exchange;}Bean(Queue1)public Queue getQueue1(){Queue build QueueBuilder.nonDurable(QUEUENAME1).build();return build;}Bean(Queue2)public Queue getQueue2(){Queue build QueueBuilder.nonDurable(QUEUENAME2).build();return build;}Bean(Binding1)public Binding bindingQueueToExchange1(Qualifier(Exchange)Exchange exchange,Qualifier(Queue1) Queue queue){Binding noargs BindingBuilder.bind(queue).to(exchange).with(test.#).noargs();return noargs;}Bean(Binding2)public Binding bindingQueueToExchange2(Qualifier(Exchange)Exchange exchange,Qualifier(Queue2) Queue queue){Binding noargs BindingBuilder.bind(queue).to(exchange).with(test.*).noargs();return noargs;} } 六、测试类 import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.context.SpringBootTest;import javax.annotation.Resource;SpringBootTest public class ProductTest {Value(${mq.exchange.name})private String EXCHANGENAME;ResourceRabbitTemplate rabbitTemplate;org.junit.jupiter.api.Testpublic void t1(){rabbitTemplate.convertAndSend(EXCHANGENAME,test.t,随便测试);} } 七. 消费者消费消息 Component public class Comm {RabbitListener(queues test_topic_exchange_queue1)public void t1(Message message){byte[] body message.getBody();String string new String(body);System.out.println(string----------------);}}八、消息的可靠性传递 1.Confirm (1) 修改application.yml文件 (2) 写一个测试类 SpringBootTest public class ProductTest {Value(${mq.exchange.name})private String EXCHANGENAME;ResourceRabbitTemplate rabbitTemplate;org.junit.jupiter.api.Testpublic void t2(){rabbitTemplate.setConfirmCallback(new RabbitTemplate.ConfirmCallback() {Overridepublic void confirm(CorrelationData correlationData, boolean b, String s) {if (b) {System.out.println(发送成功);}else {System.out.println(发送不成功s);}}});rabbitTemplate.convertAndSend(EXCHANGENAME,test.t,随便测试);} } 2. Return (1) 配置文件中设置回退模式 spring:rabbitmq:username: userpassword: 123456virtual-host: /adminport: 5672host: 192.168.44.64publisher-returns: true # publisher-confirm-type: correlated mq:exchange:name: test_exchange_topicqueue:name1: test_topic_exchange_queue1name2: test_topic_exchange_queue2 (2) 测试 import org.springframework.amqp.rabbit.connection.CorrelationData; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.context.SpringBootTest;import javax.annotation.Resource;SpringBootTest public class ProductTest {Value(${mq.exchange.name})private String EXCHANGENAME;ResourceRabbitTemplate rabbitTemplate;org.junit.jupiter.api.Testpublic void t1(){rabbitTemplate.convertAndSend(EXCHANGENAME,test.t,随便测试);}org.junit.jupiter.api.Testpublic void t2(){rabbitTemplate.setConfirmCallback(new RabbitTemplate.ConfirmCallback() {Overridepublic void confirm(CorrelationData correlationData, boolean b, String s) {if (b) {System.out.println(发送成功);}else {System.out.println(发送不成功s);}}});rabbitTemplate.convertAndSend(EXCHANGENAME,test.t,随便测试);}org.junit.jupiter.api.Testpublic void t3(){rabbitTemplate.setMandatory(true);rabbitTemplate.setReturnsCallback(returnedMessage -System.out.println(消息回退new String(returnedMessage.getMessage().getBody())));rabbitTemplate.convertAndSend(EXCHANGENAME,test.a,测试测试);} }
http://www.pierceye.com/news/660243/

相关文章:

  • 网站后台模板html5淄博桓台网站建设公司
  • 开发app和网站的公司网站开发项目流程图模板
  • 深圳优秀网站建设品牌策略
  • 上海市建设机械行业协会网站石家庄最新招聘
  • Wordpress垂直类目站模版建设官网入口
  • 网站建设发布平台网络界面设计
  • rss 网站插件国内哪个网站做水产比较大
  • 做营销看的网站有哪些内容芜湖做网站推广有哪些公司
  • 网站建设岗位说明新网金商网站
  • 网站域名使用费多少正规抖音代运营公司排名
  • 网站建设后需要交费吗物流公司电话
  • 网站建设 福州wordpress静态文件目录下
  • 鸿顺里网站建设汕头网站排名优化报价
  • 揭阳自助建站软件社区网站建设资金申请
  • 牟平做网站衡水网页网站建设
  • 蒙文门户网站建设phpok企业建站系统
  • 域名注册网站的域名哪里来的楚雄建网站
  • 专门教ps的网站简单的app开发制作
  • 电商网站建设综述湖北seo网站设计
  • 南京做网站营销网站后台忘记账号密码
  • 敦化建设局网站饰品做国际贸易哪些网站
  • 网站做js跳转怎么创建公司
  • 网站建设合同需要交印花税吗怎么做网站卖美瞳
  • 小程序价格为什么比网站建设高自定义wordpress的实用技巧
  • 企业网站模板源码有哪些报价网站制作
  • 网站建设与网页设计实训报告二级建造师建设云网站
  • 网站后缀gov汕头网站建设小程序
  • 一个空间做多个网站wordpress大改动
  • 桂林北站到机场大巴专线时刻表wordpress 分类 标签
  • 自媒体网站源码模板dede重庆永川网站建设报价