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

就业指导中心网站建设总结旺道seo软件技术

就业指导中心网站建设总结,旺道seo软件技术,深圳推广系统哪家好,珠海自助建站再SpringBoot中使用MQ 1.创建SpringBoot项目 除了我们平常使用的一些工具依赖,还需要选择这个Spring for RabbitMQ依赖 2.需要在application.yml文件中进行配置 server:port :9090 spring:application:name:producerrabbitmq:host: 你的主机名port: 5672virtual-…

再SpringBoot中使用MQ

1.创建SpringBoot项目

除了我们平常使用的一些工具依赖,还需要选择这个Spring for RabbitMQ依赖

2.需要在application.yml文件中进行配置

server:port :9090
spring:application:name:producerrabbitmq:host: 你的主机名port: 5672virtual-host: 虚拟主机名称username: adminpassword: admin123

3.测试使用

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;@RestController
public class TestController {@Resourceprivate TestService testService;@RequestMapping("test")public String test(String msg){testService.sendMsg(msg);return "success";}
}
@Service
public class TestService {@Resourceprivate AmqpTemplate amqpTemplate; // 注入RabbitMQ的模板对象,用于发送消息@Overridepublic void sendMsg(String msg) {// 发送消息到队列amqpTemplate.convertAndSend("queue1", msg);// 发送消息到交换机(订阅交换机,第二个参数为空)amqpTemplate.convertAndSend("wx1", "", msg);// 发送消息到交换机(路由交换机,第二个参数为路由key)amqpTemplate.convertAndSend("wx2", "a", msg);}
}

完善一下测试使用类

import javax.annotation.Resource;@Service
public class TestService {@Resourceprivate AmqpTemplate amqpTemplate;public void sendMsg(String msg) {if (msg.startsWith("q_")) {// 发送消息到队列amqpTemplate.convertAndSend("queue1", msg);} else if (msg.startsWith("f_")) {// 发送消息到交换机(订阅交换机)amqpTemplate.convertAndSend("ex1", "", msg);} else if (msg.startsWith("r_")) {// 发送消息到交换机(路由交换机)if (msg.startsWith("r_a")) {amqpTemplate.convertAndSend("ex2", "a", msg);} else if (msg.startsWith("r_b")) {amqpTemplate.convertAndSend("ex2", "b", msg);}}}
}

此时从浏览器发送请求:localhost:9090/test?msg=....就可以发送消息到队列中

4.然后创建消费者项目

前期步骤一致,只是配置文件的端口号进行变更

package com.qfedu.consumer.service;import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;@Service
//@RabbitListener(queues ={"queue1","queue2"})
// 首先通过RabbitListener注解监听队列
@RabbitListener(queues = "queue1")
public class ReceiveMsgService {// 然后通过RabbitHandler注解将队列中的数据作为入参使用@RabbitHandlerpublic void receiveMsg(String msg) {System.out.println("接收Msg:" + msg);}// 另一个可能的消息接收方法,处理字节数组类型的数据//@RabbitHandler//public void receiveMsg(byte[] bs) {//    // 处理字节数组的逻辑//}
}

此时就在SpringBoot中实现了生产者发送消息,然后消费者消费消息!!

http://www.hkea.cn/news/840553/

相关文章:

  • 网站建设背景朝阳百度新闻网页
  • 专门做拼团的网站西安网站开发
  • 怎么看网站开发语言太原seo推广
  • 什么网站做宣传好新乡网站seo
  • 济南网站制作服务价格信息流优化师前景
  • 新手制作网站工具bt磁力猪
  • 怎么做网站系统深圳头条新闻
  • 北京网站设计公司新鸿儒seo公司的选上海百首网络
  • 百姓网二手拖拉机百度seo优化排名客服电话
  • 北京南站是丰台站吗seo优化什么意思
  • 外贸营销型建站关键词全网搜索工具
  • 有什么网站可以做扣扣头像腾讯企点app下载安装
  • 网站设计怎么做链接拉新推广怎么快速拉人
  • 怎么自己做礼品网站补肾壮阳吃什么药效果好
  • 网站用户建设的设计与实现网站推广营销运营方式
  • html5韩国网站模板seo网站优化培训班
  • 网站被iframe信息推广的方式有哪些
  • 通信技术公司网站建设app推广代理
  • 做电影网站会违法吗营销说白了就是干什么的
  • 用外链技术做视频网站关键词在线听免费
  • 做网站常用的css最近三天的新闻热点
  • 全国人大常委会副委员长登封seo公司
  • 顶岗实践网站开发推广管理
  • 九号公司网站优化效果
  • 模板网站建设方案北京seo排名收费
  • 做箱包关注哪个网站泰州seo平台
  • 如何给网站做流量站长工具seo
  • 桂林网站开发建设推广任务接单平台
  • 化妆品 网站建设案例seo超级外链工具免费
  • 网站建设的广告语seo自动工具