位置: IT常识 - 正文

RabbitMQ学习笔记(rabbitmq中文手册)

编辑:rootadmin
RabbitMQ 整合RabbitMQ /** * 使用RabbitMQ * 1、引入ampq场景,RabbitAutoConfiguration 就会自动生效 * 2、给容器中自动配置了 * RabbitTemplate、AmqpAdmin、CachingConnectionFactory、Rab ... RabbitMQ整合RabbitMQ/** * 使用RabbitMQ * 1、引入ampq场景,RabbitAutoConfiguration 就会自动生效 * 2、给容器中自动配置了 * RabbitTemplate、AmqpAdmin、CachingConnectionFactory、RabbitMessagingTemplate * 所有的属性都是在 * @EnableConfigurationProperties(RabbitProperties.class) * @ConfigurationProperties(prefix = "spring.rabbitmq") * public class RabbitProperties * 3、给配置文件中配置 spring.rabbitmq 信息 * 4、@EnableRabbit 开启功能 * 5、监听消息:使用 @RabbitListener,必须有 @EnableRabbit * @RabbitListener:类 + 方法上 * @RabbitHandler: 只能标在方法上 */<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-amqp</artifactId></dependency># rabbit 配置文件spring.rabbitmq.host=192.168.106.101spring.rabbitmq.port=5672spring.rabbitmq.virtual-host=/

推荐整理分享RabbitMQ学习笔记(rabbitmq中文手册),希望有所帮助,仅作参考,欢迎阅读内容。

RabbitMQ学习笔记(rabbitmq中文手册)

文章相关热门搜索词:rabbitmq入门案例,rabbitmq入门到精通,rabbit mq教程,rabbitmq入门,rabbitmq简书,rabbitmq入门,rabbit mq教程,rabbit mq教程,内容如对您有帮助,希望把文章链接给更多的朋友!

测试

package com.atguigu.gulimall.order;import com.atguigu.gulimall.order.entity.OrderReturnApplyEntity;import lombok.extern.slf4j.Slf4j;import org.junit.Test;import org.junit.runner.RunWith;import org.springframework.amqp.core.AmqpAdmin;import org.springframework.amqp.core.Binding;import org.springframework.amqp.core.DirectExchange;import org.springframework.amqp.core.Queue;import org.springframework.amqp.rabbit.core.RabbitTemplate;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.boot.test.context.SpringBootTest;import org.springframework.test.context.junit4.SpringRunner;import java.util.Date;@Slf4j@RunWith(SpringRunner.class)@SpringBootTestpublic class GulimallOrderApplicationTests { @Autowired AmqpAdmin amqpAdmin; @Autowired RabbitTemplate rabbitTemplate; /** * 1、创建Exchange[hello.java.exchange]、Queue、Binding * - 使用 AmqpAdmin 进行创建 * * 2、如何收发消息 -> RabbitTemplate * 如果发送的消息是个对象,使用序列化机制,将对象写出去,对象实现 Serializable 接口 * 自定义序列化添加配置 * @Configuration * public class MyRabbitConfig { * @Bean * public MessageConverter messageConverter() { * return new Jackson2JsonMessageConverter(); * } * } */ @Test public void sendMessageTest() { String msg = "Hello World"; OrderReturnApplyEntity orderReturnApplyEntity = new OrderReturnApplyEntity(); orderReturnApplyEntity.setId(1L); orderReturnApplyEntity.setSkuName("华为"); orderReturnApplyEntity.setCreateTime(new Date()); rabbitTemplate.convertAndSend("hello.java.exchange", "hello.java", orderReturnApplyEntity); log.info("消息发送完成:{}", orderReturnApplyEntity); } @Test public void createExchange() { //amqpAdmin /** * DirectExchange * public DirectExchange(String name, boolean durable, boolean autoDelete, Map<String, Object> arguments) */ DirectExchange exchange = new DirectExchange("hello.java.exchange", true,false); amqpAdmin.declareExchange(exchange); log.info("Exchange[{}]创建成功", "hello.java.exchange"); } @Test public void createQueue() { /** * public Queue(String name, boolean durable, boolean exclusive, boolean autoDelete) */ Queue queue = new Queue("hello-java-queue", true, false,true); amqpAdmin.declareQueue(queue); log.info("Queue[{}]创建成功", "hello-java-queue"); } @Test public void createBinding() { /** * public Binding(String destination【目的地】, * DestinationType destinationType【目的地类型】, * String exchange【交换机】, * String routingKey【路由键】, * Map<String, Object> arguments)【参数】 * 将 exchange 指定交换机和 destination目的地进行绑定,使用routingKey作为指定路由键 */ Binding binding = new Binding("hello-java-queue", Binding.DestinationType.QUEUE,"hello.java.exchange","hello.java",null); amqpAdmin.declareBinding(binding); log.info("Binding == 创建成功"); }}

测试监听消息

/** * queues:
本文链接地址:https://www.jiuchutong.com/zhishi/309258.html 转载请保留说明!

上一篇:如何禁用WordPress的XML-RPC功能(如何禁用笔记本键盘触摸板)

下一篇:如何打开phpcms网站的数据库配置文件(开启php)

  • b站720p60什么意思(b站720p 60帧)

  • ac是什么键(ac是什么键计算器)

  • 秘乐短视频怎么注销账号(秘乐短视频怎么做任务)

  • qq的隐藏会话有什么用(qq隐藏会话有聊天记录吗)

  • 微博能不能设置不让某个人看(微博能不能设置别人看不到我的关注)

  • 苹果照片为什么同步不了(苹果照片为什么会动)

  • 微信上有一个小耳朵 是干嘛的(微信上有一个小图标是怎么回事)

  • 应用宝卸载了会怎样(应用宝卸载了会有记录吗)

  • 支付宝商家订单号可以查询什么信息(支付宝商家订单号怎么退款)

  • 华为手机怎样召唤语音助手(华为手机怎样召唤小易)

  • 美团乐跑有时间限制吗(美团乐跑有时间段要求吗)

  • html查看器在哪找到(html如何查看)

  • 新买的手机号码被别人注册微信怎么办(新买的手机号码支付宝被注册了怎么办)

  • 为什么抖音用微信登录说没有获得权限(为什么抖音用微信登不上有权限)

  • 手机怎么记考勤(手机怎么记考勤?)

  • 苹果没备份照片怎么恢复(苹果没备份照片能恢复)

  • iqoo和iqoopro的外观差别(iqoo pro iqoo)

  • word中版式选项卡在哪里(word中版式设计在哪)

  • 屏幕出现圆圈怎么关闭(屏幕出现圆圈怎么关闭 苹果)

  • 华为碎屏险在哪里查看(华为碎屏险在哪里买划算?)

  • 图片打码怎么去掉(图片打码怎么去掉美图秀秀)

  • 苹果x前置摄像头黑屏怎么办(苹果x前置摄像头)

  • 三星s9相册回收站在哪(三星s9照片回收怎么找回)

  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设 电脑维修 湖南楚通运网络