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

网站开发优惠活动方案电工培训学校

网站开发优惠活动方案,电工培训学校,oppo开放平台,广东东远建设工程管理有限公司网站0、知识点 1、创建项目-生产者 默认官方start.spring.io已不支持自动生成低版本jkd的Spring项目,自定义用阿里云的starter即可:https://start.aliyun.com 2、创建配置类 package com.wym.rabbitmqprovider.utils;import org.springframework.amqp.core.…

0、知识点

1、创建项目-生产者

        默认官方start.spring.io已不支持自动生成低版本jkd的Spring项目,自定义用阿里云的starter即可:https://start.aliyun.com

2、创建配置类

package com.wym.rabbitmqprovider.utils;import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;@Configuration
public class DirectRabbitConfig {//队列 起名:TestDirectQueue@Beanpublic Queue TestDirectQueue() {// durable:是否持久化,默认是false,持久化队列:会被存储在磁盘上,当消息代理重启时仍然存在,暂存队列:当前连接有效// exclusive:默认也是false,只能被当前创建的连接使用,而且当连接关闭后队列即被删除。此参考优先级高于durable// autoDelete:是否自动删除,当没有生产者或者消费者使用此队列,该队列会自动删除。//   return new Queue("TestDirectQueue",true,true,false);//一般设置一下队列的持久化就好,其余两个就是默认falsereturn new Queue("TestDirectQueue",true);}//Direct交换机 起名:TestDirectExchange@BeanDirectExchange TestDirectExchange() {//  return new DirectExchange("TestDirectExchange",true,true);return new DirectExchange("TestDirectExchange",true,false);}//绑定  将队列和交换机绑定, 并设置用于匹配键:TestDirectRouting@BeanBinding bindingDirect() {return BindingBuilder.bind(TestDirectQueue()).to(TestDirectExchange()).with("TestDirectRouting");}@BeanDirectExchange lonelyDirectExchange() {return new DirectExchange("lonelyDirectExchange");}}

3、创建消息发送接口

package com.wym.rabbitmqprovider.controller;import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;@RestController
public class SendMessageController {@AutowiredRabbitTemplate rabbitTemplate;  //使用RabbitTemplate,这提供了接收/发送等等方法@GetMapping("/sendDirectMessage")public String sendDirectMessage() {String messageId = String.valueOf(UUID.randomUUID());String messageData = "test message, hello!";String createTime = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));Map<String,Object> map=new HashMap<>();map.put("messageId",messageId);map.put("messageData",messageData);map.put("createTime",createTime);//将消息携带绑定键值:TestDirectRouting 发送到交换机TestDirectExchangerabbitTemplate.convertAndSend("TestDirectExchange", "TestDirectRouting", map);return "ok";}
}

4、使用postapi测试

 5、查看客户端

 queues中也有了

 6、补充:导包、yml配置

 <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-amqp</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency>
server:port: 8081
spring:#给项目来个名字application:name: rabbitmq-provider#配置rabbitMq 服务器rabbitmq:host: 127.0.0.1port: 5672username: guestpassword: guest#虚拟host 可以不设置,使用server默认host#-host: host

OK,接下来做消费者:Springboot集成RabbitMq二-CSDN博客

http://www.yidumall.com/news/35250.html

相关文章:

  • 宝塔做的网站网页打不开网络推广业务
  • 网站域名绑定好处网站推广方案有哪些
  • 把收藏夹网站设置成主业怎么做做网站推广公司
  • 页面设计教程山东seo网络推广
  • 丹徒网站建设公司seo专业技术培训
  • 如何网站制作seo综合优化公司
  • 微企免费做网站网站外链工具
  • 高端定制网站开发需要多少钱青岛百度seo代理
  • 广东专业做网站排名公司哪家好长沙关键词优化平台
  • 綦江网站建设公司竞价托管外包费用
  • 建站网站abcseo网络营销招聘
  • wordpress 编辑菜单网站优化排名工具
  • 全屋定制十大名牌口碑分析网站推广和优化的原因
  • 龙华网站制作要多少钱免费推广平台
  • 高端网站淘宝运营培训
  • 网站建设如何提案福州短视频seo机会
  • 游戏公司做网站设计赚钱吗焦作seo公司
  • 终端平台网站建设抖音广告
  • python网站开发用什么数据库小学培训机构
  • 广州led网站建设足球直播在线直播观看免费cctv5
  • 九江建筑工程有限公司seo都用在哪些网站
  • 网址导航怎么彻底删除关键词排名优化公司哪家好
  • 网站建设活动策划方案百度网盘服务电话6988
  • 代理网络游戏平台百度seo指数查询
  • 河北石家庄地图北京seo关键词优化收费
  • html5开发的网站网页设计软件dreamweaver
  • 网站开发培训周末班网址注册查询
  • 新疆维吾尔族城乡建设厅网站厦门网站建设平台
  • 北京高端网站建设网站制作
  • 国内真人做爰视频直播网站做网站哪个公司最好