当前位置: 首页 > 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.yayakq.cn/news/203655/

相关文章:

  • 国外ui设计网站制作和维系一个网站的费用
  • 有没有可以做各种字体的网站外贸网站建设原则
  • 网站建设的目的只是开展网络营销网站服务器 安全
  • 泰兴市城乡住房建设局网站中国机械工业网
  • 南宁软件优化网站网站建设绩效考核方案
  • 做防水怎么注册网站电子商务网站建设影响因素
  • 网站建设的专业性对搜索引擎营销的影响网站建设的会计分录
  • 做视频网站用什么源码wordpress 必备
  • 网站开发的大学生应届简历wordpress 管理插件
  • 汕头在线制作网站四川手机网站开发
  • iis 网站启动不了做非法网站怎么盈利
  • 网站建设的认可wordpress foreign trade
  • 灰色网站设计合肥网站建设哪里好
  • 广州外贸公司集中地南京网站优化
  • 网站推广外链wordpress换中文
  • php网站开发干嘛的淅川微网站建设
  • 什么是网站主机asp网站建设技术方案
  • 哪个网站做ic外单好网站建设建站经验
  • 广州网站设计联系方式网站开发需要什么步骤
  • 世界上网站做的好的例子WordPress主题开发核心知识
  • 旅游网站设计报告电子商务网站建设推广分析
  • 电子商务网站开发与设计wordpress 置顶
  • 微信手机网站三合一东莞做网站网站
  • 磐安县住和城乡建设局网站大数据营销优势
  • 最早做团购的网站网站开发交接清单
  • 动力启航做网站wordpress 主题 2016
  • 开发网站需要哪些技术人员贵阳58同城做网站
  • 石家庄网站定制制作wordpress设置后台自定义功能选项
  • 周口城乡建设局网站wordpress换域名换服务器
  • wordpress手机访问网站seo 文章转载 修改标题