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

学做美食视频网站谷歌搜索入口 镜像

学做美食视频网站,谷歌搜索入口 镜像,旧版百度网址大全下载,如何开发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.ritt.cn/news/2167.html

相关文章:

  • 上海松江网站建设公司免费发布推广信息的软件
  • 如何在家做电商seo服务是什么
  • 网站建设公司找哪家好如何软件网站优化公司
  • 除了Joomla用什么做网站好淘宝优化
  • 单页网站怎么做竞价seo优化软件有哪些
  • 区块链软件开发seo优化名词解释
  • 网上做网站广告需要身份证吗电商网站建设步骤
  • 龙岗网站制作seo翻译
  • 做购物网站公司惠州关键词排名提升
  • 个人网站如何制作营销软文
  • 舟山新闻最新消息海外seo网站推广
  • 凡客网站规划与建设ppt网站网址查询工具
  • 免费建网站空间专业放心关键词优化参考价格
  • 青岛哪里有做网站的产品网络推广的方法
  • 男女做那个的网站汕头网站快速优化排名
  • 比较好的做外贸网站seo排名怎么样
  • vs2008 手机网站开发酒店如何进行网络营销
  • 海口自助建站系统杭州seo网站优化公司
  • 如何自己创造网站seo工具大全
  • 如何提高网站pr值今日最新消息新闻
  • 有pc网站网站优化排名怎么做
  • 网站建站素材连云港seo公司
  • 高校网站建设方案专门培训seo的网站
  • 网站建设的特点2022年明星百度指数排行
  • 自己如何免费做网站线上营销的优势
  • 长宁区网站建设网2022真实新闻作文400字
  • 用iis做的网站怎么更改端口山东建站
  • 小型网站运营合肥网站优化平台
  • 免费开源企业网站网络营销推广难做吗
  • 重庆品牌网站建设公司网站推广的概念