28、springboot整合RabbitMQ(2)
1、监听
@Service
public class BookService {
@RabbitListener(queues = "atguigu.news")
public void receive(Book book){
System.out.println("收到消息:" + book);
}
}
开启关于RabbitMq注解
//开启基于注解RabbitMq模式
@EnableRabbit
@SpringBootApplication
public class AmqpApplication { public static void main(String[] args) {
SpringApplication.run(AmqpApplication.class, args);
}
}
后台的监听结果

1.2、获取消息头、消息体相关的参数

import org.springframework.stereotype.Service; @Service
public class BookService {
@RabbitListener(queues = "atguigu.news")
public void receive(Book book){
System.out.println("收到消息:" + book);
} //import org.springframework.amqp.core.Message;
@RabbitListener(queues = "atguigu")
public void receive02(Message message){
System.out.println(message.getBody());
System.out.println(message.getMessageProperties());
} }
打印的数据
[B@2d4a67c8
MessageProperties [headers={__TypeId__=com.cr.amqp.pojo.Book}, contentType=application/json, contentEncoding=UTF-, contentLength=, receivedDeliveryMode=PERSISTENT, priority=, redelivered=true, receivedExchange=exchange.fanout, receivedRoutingKey=, deliveryTag=, consumerTag=amq.ctag-193ojwCpIAgVmLfB52Prkg, consumerQueue=atguigu]
收到消息:com.cr.amqp.pojo.Book@74095f6e
2、创建

@Autowired
AmqpAdmin amqpAdmin;
//创建交换器
@Autowired
AmqpAdmin amqpAdmin; public void createExchange(){ //package org.springframework.amqp.core;
//public interface Exchange extends Declarable
amqpAdmin.declareExchange(new DirectExchange("amqp.exchange"));
}
结果:

交换器的类:

创建队列:
amqpAdmin.declareQueue(new Queue("amqpadmin.queue"));

绑定规则:
//绑定规则
amqpAdmin.declareBinding(new Binding("amqpadmin.queue",Binding.DestinationType.QUEUE,"amqp.exchange","amqp.aa",null));

28、springboot整合RabbitMQ(2)的更多相关文章
- springboot学习笔记-6 springboot整合RabbitMQ
一 RabbitMQ的介绍 RabbitMQ是消息中间件的一种,消息中间件即分布式系统中完成消息的发送和接收的基础软件.这些软件有很多,包括ActiveMQ(apache公司的),RocketMQ(阿 ...
- 【SpringBoot系列5】SpringBoot整合RabbitMQ
前言: 因为项目需要用到RabbitMQ,前几天就看了看RabbitMQ的知识,记录下SpringBoot整合RabbitMQ的过程. 给出两个网址: RabbitMQ官方教程:http://www. ...
- SpringBoot系列八:SpringBoot整合消息服务(SpringBoot 整合 ActiveMQ、SpringBoot 整合 RabbitMQ、SpringBoot 整合 Kafka)
声明:本文来源于MLDN培训视频的课堂笔记,写在这里只是为了方便查阅. 1.概念:SpringBoot 整合消息服务 2.具体内容 对于异步消息组件在实际的应用之中会有两类: · JMS:代表作就是 ...
- 一篇学习完rabbitmq基础知识,springboot整合rabbitmq
一 rabbitmq 介绍 MQ全称为Message Queue,即消息队列, RabbitMQ是由erlang语言开发,基于AMQP(Advanced MessageQueue 高级消息队列协议 ...
- 【MQ中间件】RabbitMQ -- SpringBoot整合RabbitMQ(3)
1.前言说明 前面一篇博客中提到了使用原生java代码进行测试RabbitMQ实现多种交换机类型的队列场景.但是在项目中我们一般使用SpringBoot项目,而且RabbitMQ天生对于Spring的 ...
- 功能:SpringBoot整合rabbitmq,长篇幅超详细
SpringBoot整合rabbitMq 一.介绍 消息队列(Message Queue)简称mq,本文将介绍SpringBoot整合rabbitmq的功能使用 队列是一种数据结构,就像排队一样,遵循 ...
- springboot整合rabbitmq实现生产者消息确认、死信交换器、未路由到队列的消息
在上篇文章 springboot 整合 rabbitmq 中,我们实现了springboot 和rabbitmq的简单整合,这篇文章主要是对上篇文章功能的增强,主要完成如下功能. 需求: 生产者在启 ...
- Springboot 整合RabbitMq ,用心看完这一篇就够了
该篇文章内容较多,包括有rabbitMq相关的一些简单理论介绍,provider消息推送实例,consumer消息消费实例,Direct.Topic.Fanout的使用,消息回调.手动确认等. (但是 ...
- RabbitMQ入门到进阶(Spring整合RabbitMQ&SpringBoot整合RabbitMQ)
1.MQ简介 MQ 全称为 Message Queue,是在消息的传输过程中保存消息的容器.多用于分布式系统 之间进行通信. 2.为什么要用 MQ 1.流量消峰 没使用MQ 使用了MQ 2.应用解耦 ...
- SpringBoot 整合 RabbitMQ 实现消息可靠传输
消息的可靠传输是面试必问的问题之一,保证消息的可靠传输主要在生产端开启 comfirm 模式,RabbitMQ 开启持久化,消费端关闭自动 ack 模式. 环境配置 SpringBoot 整合 Rab ...
随机推荐
- js 千分位符号 正则方法
function toThousands(num) { return (num || 0).toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,');}
- 05-Servlet与内部加载机制(part1)
一.什么是Servlet Servlet 运行在服务端的Java小程序, 是sun公司提供一套规范(接口) 主要功能: 用来处理客户端请求 响应给浏览器的动态资源 servlet的实质就是j ...
- HDFS 的运行机制
hdfs haddop distributed system 由 name node, secondary name node,data node, client 组成. 真正存放数据的就是 data ...
- input textarea监听鼠标粘贴
发现一个问题,在input/textarea中如果是鼠标粘贴内容进去,发现判断不了value的改变,html代码如下: <!doctype html> <html> <h ...
- 项目经验:GIS<MapWinGIS>建模第二天
记录下GIS的进展情况
- Android 自定义简易的方向盘操作控件
最近在做一款交互性较为复杂的APP,需要开发一个方向操作控件.最终用自定义控件做了一个简单的版本. 这里我准备了两张素材图,作为方向盘被点击和没被点击的背景图.下面看看自定义的Wheel类 publi ...
- PHP计算近1年的所有月份
$z = date('Y-m'); $a = date('Y-m', strtotime('-12 months')); $begin = new DateTime($a); $end = new D ...
- 基于PMBOK的项目管理知识体系
- react native学习资料
一:基础学习: react-native中文文档(react native中文网,人工翻译,官网完全同步)http://react-native.cn/docs/getting-started.htm ...
- 初识WCF2
参照: http://blog.csdn.net/songyefei/article/details/7371571 在上一篇中,我们在一个控制台应用程序中编写了一个简单的WCF服务并承载了它.先回顾 ...