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

百度网站建设是什么360搜索引擎下载

百度网站建设是什么,360搜索引擎下载,上海人才服务网官网,wordpress和主题1.首先是创建项目 在一个父工程 mq_demo 的基础上建立两个子模块,生产者模块publisher,消费者模块 consumer 创建项目: 建立成功: 删除多余文件 创建子模块1:publisher(生产者模块) 右键---…

1.首先是创建项目

在一个父工程 mq_demo 的基础上建立两个子模块,生产者模块publisher,消费者模块 consumer
创建项目:
在这里插入图片描述
建立成功:
在这里插入图片描述
删除多余文件
在这里插入图片描述
创建子模块1:publisher(生产者模块)
右键-----new ----module
在这里插入图片描述
选中Java,填写publisher,选中maven,确认父模块
在这里插入图片描述
创建成功
在这里插入图片描述
同理:创建子模块2:consumer(消费者模式)
在这里插入图片描述
至此:项目创建完毕

2.进行基本配置(pom.xml、application.yml)

引入依赖:父模块引入依赖,子模块共享父模块依赖

pom.xml

<dependencies><!--AMQP依赖,包含 rabbitmq --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-amqp</artifactId></dependency><!--单元测试--><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.13.2</version><scope>test</scope></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency></dependencies>

application.yml

logging:pattern:dateformat: yyyy-MM-dd HH:mm:ss.SSSlevel:mq.listener:  debug
spring:rabbitmq:host: 127.0.0.1port: 5672username: guestpassword: guestvirtual-host: /

结构图:
在这里插入图片描述
建立具体的包结构,以及要用的一些类
在这里插入图片描述
消费者启动类:ConsumerApplication.class

@SpringBootApplication
public class ConsumerApplication {public static void main(String[] args) {SpringApplication.run(ConsumerApplication.class, args);}}

生产者启动类:PublisherApplication.class

@SpringBootApplication
public class PublisherApplication {public static void main(String[] args) {org.springframework.boot.SpringApplication.run(PublisherApplication.class, args);}
}

消费者监听类:SpringRabbitListerner.class

@Component
public class SpringRabbitListerner {@RabbitListener(queues = "queue.simple")public void listenSimpleQueueMessage(String msg){System.out.println("简单模式-消费者消费消息:"+msg);}
}

生产者启动类:SpringAmqpTest.class

@ExtendWith(SpringExtension.class)
@SpringBootTest
public class SpringAmqpTest {@Autowiredprivate RabbitTemplate  rabbitTemplate;@Testpublic void testSendSimpleMessage() {String simpleQueue = "queue.simple";String message = "hello world";rabbitTemplate.convertAndSend(simpleQueue,message);}
}

做到这里,就已经可以进行mq的消息进行发送和获取了。

3.Spring AMQP的五种工作模式

生产者启动类:SpringAmqpTest.class

@ExtendWith(SpringExtension.class)
@SpringBootTest
public class SpringAmqpTest {@Autowiredprivate RabbitTemplate  rabbitTemplate;@Testpublic void testSendSimpleMessage() {String simpleQueue = "queue.simple";String message = "hello world";rabbitTemplate.convertAndSend(simpleQueue,message);}@Testpublic void testSendWorkQueue(){String workQueue = "queue.work";for(int i=1 ;i<=10;i++){String message = "hello world.."+i;rabbitTemplate.convertAndSend(workQueue,message);}}@Testpublic void testSendFanout(){String fanoutExchange = "amq.fanout";String message = "hello world fanout..";rabbitTemplate.convertAndSend(fanoutExchange,"",message);}@Testpublic void testSendDirect(){String directExchange = "amq.direct";String message = "hello world direct..";rabbitTemplate.convertAndSend(directExchange,"red",message);}}

消费者监听类:SpringRabbitListerner.class

@Component
public class SpringRabbitListerner {@RabbitListener(queues = "queue.simple")public void listenSimpleQueueMessage(String msg){System.out.println("简单模式-消费者消费消息:"+msg);}@RabbitListener(queues = "queue.work")public void listenWorkQueueMessage1(String msg){System.out.println("工作模式-消费者消费消息:"+msg);}@RabbitListener(queues = "queue.work")public void listenWorkQueueMessage2(String msg){System.out.println("工作模式-消费者消费消息2:"+msg);}@RabbitListener(queues = "queue.fanout1")public  void listenFanoutQueueMessage1(String msg){System.out.println("发布订阅模式-消费者1消费消息:"+msg);}@RabbitListener(queues = "queue.fanout2")public  void listenFanoutQueueMessage2(String msg){System.out.println("发布订阅模式-消费者2消费消息:"+msg);}@RabbitListener(queues = "queue.direct1")public void listenDirectQueueMessage(String msg){System.out.println("路由模式-消费者消费消息:"+msg);}@RabbitListener(queues = "queue.direct2")public void listenTopicQueueMessage1(String msg){System.out.println("路由模式-消费者1消费消息:"+msg);}}

所用到的配置类:
主要是建立交换机、建立队列、绑定交换机和队列关系的
订阅者模式

@Configuration
public class FunoutConfig {@Beanpublic FanoutExchange fanoutExchange() {return new FanoutExchange("amq.fanout");}@Beanpublic Queue  queue1() {return new Queue("queue.fanout1");}@Beanpublic Queue   queue2() {return new Queue("queue.fanout2");}@Beanpublic Binding binding1(Queue queue1, FanoutExchange fanoutExchange) {return BindingBuilder.bind(queue1).to(fanoutExchange);}@Beanpublic Binding binding2(Queue queue2, FanoutExchange fanoutExchange) {return BindingBuilder.bind(queue2).to(fanoutExchange);}}

路由模式

@Configuration
public class DirectConfig {@Beanpublic DirectExchange directExchange(){return new DirectExchange("amq.direct");}@Beanpublic Queue directQueue1(){return new Queue("queue.direct1");}@Beanpublic Queue directQueue2(){return new Queue("queue.direct2");}@Beanpublic Binding  directBinding1(Queue queue1, DirectExchange directExchange){return BindingBuilder.bind(queue1).to(directExchange).with("yellow");}@Beanpublic Binding  directBinding2(Queue queue2, DirectExchange directExchange){return BindingBuilder.bind(queue2).to(directExchange).with("red");}}
http://www.dtcms.com/wzjs/70720.html

相关文章:

  • 教学网页制作简述什么是seo
  • 扶贫工作网站怎么做seo设置是什么
  • 响应式设计的基本原理百度网站优化软件
  • 做珠宝网站价格多少网络营销的基本职能
  • 搜狗提交网站收录入口seo站长综合查询
  • 波兰 政府网站建设google官网
  • 北京大兴网站制作推广四川专业网络推广
  • 东莞网站设计公司网络推广方式主要有
  • 建设网站备案与不备案区别seo常用方法
  • 深圳网站建设推进软件推广接单平台
  • 做啥网站seo网络排名优化方法
  • 金山做企业网站东莞市网站seo内容优化
  • node怎么做网站百度软件下载安装
  • 长沙长沙建设网站长尾词挖掘工具
  • 做旅游网站挣钱吗网站不收录怎么解决
  • 怎样在门户网站做 推广注册一个域名需要多少钱
  • seo就业前景怎么样seo网站优化排名
  • 深圳便宜网站建设产品推广平台
  • 佛山专业做网站公司百度最新人工智能
  • 背景响应式网站开发 css做电商需要什么条件
  • 公司网站设计有基本哪些要求做推广app赚钱的项目
  • 睢宁微网站开发我的百度账号
  • 长春网站建设厂家国内b2b十大平台排名
  • 动态网站设计的基本流程产品市场推广计划书
  • 杭州精品课程网站建设百度信息流推广教程
  • app定制开发谈判技巧山东网络推广优化排名
  • 官方网站弹幕怎么做友情链接的网站有哪些
  • 做旅游网站的公司网站seo方案撰写
  • wordpress向登录页面跳转百度seo教程视频
  • 公安网站服务平台在线视频观看免费视频22