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

唐山市住房和城乡建设局门户网站wordpress 律师事务所模板

唐山市住房和城乡建设局门户网站,wordpress 律师事务所模板,注册网站会不会有风险,网络架构模拟设计这目录 一、添加依赖二、配置文件中添加RabbitMQ访问配置三、消息生产者代码四、消息消费者代码五、验证参考资料 一、添加依赖 <!--AMQP依赖&#xff0c;包含RabbitMQ--><dependency><groupId>org.springframework.boot</groupId><artifactId>s…

这目录

  • 一、添加依赖
  • 二、配置文件中添加RabbitMQ访问配置
  • 三、消息生产者代码
  • 四、消息消费者代码
  • 五、验证
  • 参考资料

一、添加依赖

        <!--AMQP依赖,包含RabbitMQ--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-amqp</artifactId></dependency><!-- 引入knife4j-spring-ui包 /doc.html--><dependency><groupId>com.github.xiaoymin</groupId><artifactId>knife4j-spring-boot-starter</artifactId><version>3.0.3</version></dependency>

二、配置文件中添加RabbitMQ访问配置

spring.rabbitmq.host=192.168.0.104
spring.rabbitmq.port=5672
spring.rabbitmq.virtual-host=/
spring.rabbitmq.username=admin
spring.rabbitmq.password=admin123

三、消息生产者代码

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;@Api(tags = "生产者服务")
@RestController
public class ProducerController {@Autowiredprivate RabbitTemplate rabbitTemplate;@ApiOperation(value = "基本消息模型")@PostMapping("/testHello")public String testHello() {rabbitTemplate.convertAndSend("hello","hello world");return "ok";}@ApiOperation(value = "work消息模型")@PostMapping("/testWork")public String testWork() {for (int i = 0; i < 10; i++) {rabbitTemplate.convertAndSend("work","hello work!");}return "ok";}@ApiOperation(value = "订阅模型-Fanout 广播模式")@PostMapping("/testFanout")public String testFanout() {rabbitTemplate.convertAndSend("logs","","这是日志广播");return "ok";}@ApiOperation(value = "订阅模型-Direct")@PostMapping("/testDirect")public String testDirect() {rabbitTemplate.convertAndSend("directs","error","error 的日志信息");return "ok";}@ApiOperation(value = "订阅模型-Topic")@PostMapping("/testTopic")public String testTopic() {rabbitTemplate.convertAndSend("topics","user.save.findAll","user.save.findAll 的消息");return "ok";}
}

四、消息消费者代码

import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;@Component
public class SpringRabbitListener {//基本消息模型@RabbitListener(queuesToDeclare = @Queue("hello"))public void receive(String message) {System.out.println("message = " + message);}//work消息模型@RabbitListener(queuesToDeclare = @Queue("work"))public void workReceive1(String message) {System.out.println("workReceive1 message = " + message);}//work消息模型@RabbitListener(queuesToDeclare = @Queue("work"))public void workReceive2(String message) {System.out.println("workReceive2 message = " + message);}//订阅模型-Fanout 广播模式@RabbitListener(bindings = @QueueBinding(value = @Queue, exchange = @Exchange(name="logs",type = "fanout")))public void fanoutReceive(String message) {System.out.println("fanoutReceive message = " + message);}//订阅模型-Direct@RabbitListener(bindings ={@QueueBinding(value = @Queue(),key={"info","error"},exchange = @Exchange(type = "direct",name="directs"))})public void directReceive(String message) {System.out.println("directReceive message = " + message);}//订阅模型-Topic@RabbitListener(bindings = {@QueueBinding( value = @Queue,key = {"user.*"},exchange = @Exchange(type = "topic",name = "topics"))})public void topicReceive1(String message) {System.out.println("topicReceive1 message = " + message);}//订阅模型-Topic@RabbitListener(bindings = {@QueueBinding(value = @Queue,key = {"user.#"},exchange = @Exchange(type = "topic",name = "topics"))})public void topicReceive2(String message) {System.out.println("topicReceive2 message = " + message);}}

五、验证

浏览器输入:ip:8080/doc.html 对接口逐个进行测试

参考资料

  1. RabbitMQ详解
  2. RabbitMQ五种消息模型
http://www.yayakq.cn/news/458914/

相关文章:

  • 网站建设可以用350摸板如何用asp做网站
  • 青岛网站建设公司外包wordpress简单的博客主题
  • 北京好的网站建设网页版手游
  • 佛山企业网站多少钱百度指数可以查询到哪些内容
  • 玉环建设规划局网站市场营销策划包括哪些内容
  • 个人免费注册公司网站动力无限做网站怎么样
  • 北京h5网站建设报价制作网页模板适应不同分辨率
  • 如何修改公司网站店面设计与装修
  • 桓台县建设局网站网站备案个人和企业的区别
  • 网站网上商城制作网站建设规划书怎么写
  • 花瓣按照哪个网站做的如何查看网站是不是wordpress
  • 汕头网站设计有限公司全国最缺工的100个职业排行
  • 兰州seo新站优化招商网站的工商网监怎么做进去
  • 成都网站建设服务商wordpress批量添加tag
  • 长宁区网站建设设计话色南通云网站建设
  • 怎么自己做个网站做链接跳转工程预算软件
  • 正规网站建设的公司招聘网站建设的目的
  • 企业营销型网站设计今天刚刚的最新新闻
  • 如何做网站窗口网页设计教程dw
  • 电视台网站建设方案做网页一个页面多少钱
  • 网站内容协议wordpress 404跳转到首页
  • 揭阳 网站建设二维码生成器在线制作方法
  • 做网站商城需要多少钱网站专题页面
  • 云南省建设系统网站互联网公司响应式网站
  • 民政局网站建设方案手机模板素材图片
  • seo网站内容优化有哪些wordpress头像多说
  • 网页建立网站平台服装网站设计公司
  • 网站三层结构示意图中国空间站现在有几个人
  • 有网站建设的虚拟主机管理系统网络服务类型及协议
  • 西宁市建设网站企业便宜高端网站设计推荐