Spring RabbitMq概述
Spring AMQP consists of a handful of modules, each represented by a JAR in the distribution. These modules are: spring-amqp, and spring-rabbit. The spring-amqp module contains the
org.springframework.amqp.core package.
Within that package, you will find the classes that represent the core AMQP "model".
RabbitMq系统架构,及工作流程
RabbitMq系统分为三个部分,producer, broker和consumer。 producer产生消息,将消息通过网络信道发送给部署在网络上的Amqp服务器broker的Message queue。consumer通过侦听消息队列来获取信息。

Amqp服务器Broker主要由Exchane和Message Queue组成,主要功能是Message的路由和缓存。
Exchange接受producer发送的message并根据不同的算法将Message路由给不同的queue。Message queue会在message不能被正常消费的时候缓存起来,当Consumer和Message Queue建立连接时,Message Queue会将消息传给consumer

Exchange和Message Queue之间通过Binding进行关联,Exchange和多个Queue会形成一张路由表,Exchange根据Routing Key和Exchange Type将Message路由到MessageQueue。
Binding Key由Consumer在Binding Exchange与Message Queue时指定,而Routing Key由Producer发送Message时指定,两者的匹配方式由Exchange Type决定。
Exchange Type分为Direct(单播)、Topic(组播)、Fanout(广播)。当为Direct(单播)时,Routing Key必须与Binding Key相等时才能匹配成功,当为Topic(组播)时,Routing Key与Binding Key符合一种模式关系即算匹配成功,当为Fanout(广播)时,不受限制。默认Exchange Type是Direct(单播)。
Springmq几个重要的类
Message
Spring AMQP定义的Message类是AMQP域模型中代表之一。Message类封装了body(消息BODY)和properties(消息属性),这使得API看起来很简单。 Message由Header和Body组成,Header是由Producer添加的各种属性的集合,包括Message是否被缓存、由哪个Message Queue接受、优先级是多少等。而Body是真正需要传输的APP数据。
public class Message {
private final MessageProperties messageProperties;
private final byte[] body;
public Message(byte[] body, MessageProperties
messageProperties) {
this.body = body;
this.messageProperties = messageProperties;
}
public byte[] getBody() {
return this.body;
}
public MessageProperties getMessageProperties() {
return this.messageProperties;
}
}
Exchange
Exchange代表一个AMQP交换,一个消息producer会将消息发送给Exchange。 每个Exchange都有一个唯一的名字和其他的属性。
public interface Exchange {
String getName();
String getExchangeType();
boolean isDurable();
boolean isAutoDelete();
Map<String, Object> getArguments();
}
ExchangeTypes: 基本类型包括 Direct(单播), Topic(组播), Fanout(广播), and Headers。默认为Direct Exchange
Queue
Message Consumer通过监听消息队列来获取数据
public class Queue {
private final String name;
private volatile boolean durable;
private volatile boolean exclusive;
private volatile boolean autoDelete;
private volatile Map<String, Object> arguments;
/**
* The queue is durable, non-exclusive and non auto-delete.
*
* @param name the name of the queue.
*/
public Queue(String name) {
this(name, true, false, false);
}
Binding
考虑到producer发送消息给Exchange一个consumer通过queue来接受消息,binding的作用是链接queue和exchange。
ConnectionFactory
管理到RabbitMQ broker的连接接口,具体的实现是CachingConnectionFactory类,CachingConnectionFactory为每个channel保持分离的cach。hostname可以通过构造器传入,同时我们需要提供username和pasword。ConnectionFactory可以使用rabbit namespace快速创建。 ConnectionFactory创建的channel 默认cach-size是1,我们可以使用rabbit namespace配置。
AmqpAdmin
需要为AmqpAdmin绑定指定的ConnectionFactory, 当配置了这个参数,本地的配置会在远端server生效。
RabbitTemplate
需要为RabbitTemplate绑定指定的ConnectionFactory,通过AmqpTemplate对象发送和接受消息。
Reference
http://blog.chinaunix.net/uid-22312037-id-3458208.html RabbitMQ源码解析前奏--AMQP协议
http://docs.spring.io/spring-amqp/reference/html/_reference.html#_introduction_3 Spring-amqp Reference
Spring RabbitMq概述的更多相关文章
- Spring Cloud 概述
1. Spring Cloud 引言 首先我们打开spring 的官网:https://spring.io/ 我们会看到这样一张图片 这个图片告诉我们,开发我们的应用程序就像盖楼一样, 首先我们需要搭 ...
- Spring Rabbitmq HelloWorld实例
之前的博客和大家分享了Rabbitmq的基本框架,及其工作原理,网址为 < http://www.cnblogs.com/jun-ma/p/4840869.html >.今天呢,想和大家一 ...
- Spring rabbitMq 中 correlationId或CorrelationIdString 消费者获取为null的问题
问题 在用Spring boot 的 spring-boot-starter-amqp 快速启动 rabbitMq 是遇到了个坑 消费者端获取不到:correlationId或Correlatio ...
- Spring Integration概述
1. Spring Integration概述 1.1 背景 Spring框架的一个重要主题是控制反转.从广义上来说,Spring处理其上下文中管理的组件的职责.只要组件减轻了职责,它们同 ...
- (转)Spring的概述
http://blog.csdn.net/yerenyuan_pku/article/details/69663685 Spring的概述 什么是Spring 据度娘所载: Spring是一个开源框架 ...
- 微服务与Spring Cloud概述
微服务与Spring Cloud随着互联网的快速发展, 云计算近十年也得到蓬勃发展, 企业的IT环境和IT架构也逐渐在发生变革,从过去的单体应用架构发展为至今广泛流行的微服务架构. 微服务是一种架构风 ...
- Spring IOC 概述
Spring IOC 概述 IOC(Inversion of Control) 控制反转,也叫 DI(D_ependency injection_) 依赖注入.是一种设计思想.不过我并不同意所谓反转的 ...
- RabbitMq 概述
RabbitMQ是实现了高级消息队列协议(Advanced Message Queueing Protocol , AMQP)的开源消息代理软件(亦称面向消息的中间件). 1.AMQP协议 Rocke ...
- 1.Spring 框架概述
目录 Spring 框架概述 1 我们所说的 "Spring "是什么意思 2. Spring和Spring框架的历史 3. 设计理念 4.反馈和贡献 5.开始使用 Spring ...
随机推荐
- SQL SERVER 将表中字符串转换为数字的函数 (详询请加qq:2085920154)
在SQL SERVER 2005中,将表中字符串转换为数字的函数共2个:1. convert(int,字段名) 例如:select convert(int,'3')2. cast(字段名 as i ...
- PHP的文件格式应该以UTF-8无BOM编码
前一段时间写PHP,经常在解析文件之前就要对数据进行处理判断,并以header()的方式进行页面跳转.然而后来将文件放到 linux 服务器时常碰到header()解析出错的情况,而在 windows ...
- .Net MVC+bootstrap Table学习
一.效果展示 二.使用方法 1).相关css和js的引用 <link href="~/Themes/Bootstrap/css/bootstrap.css" rel=&quo ...
- tomcat使用线程池配置高并发连接
1:配置executor属性打开/conf/server.xml文件,在Connector之前配置一个线程池:[html] view plain copy<Executor name=" ...
- Python赋值语句与深拷贝、浅拷贝的区别
参考:http://stackoverflow.com/questions/17246693/what-exactly-is-the-difference-between-shallow-copy-d ...
- php-4种排序
<?php$arr = array(1, 43, 54, 62, 21, 66, 32, 78, 36, 76, 39); //1. 冒泡排序 //在要排序的一组数中,对当前还未排好的序列,从前 ...
- XMLHttpRequest cannot load file:///E:/userdialog.html?_=1465888805734. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-reso
做前端写静态页面时,采用的是jq easyui框架 在ie与webkit总是加载的时候总是在loading... 而firefox却是正常加载的,总以为是代码写错了, 经过再三的检查以及百度查找,确认 ...
- PHP 增删改查
<h1>主页面family</h1> <table width="100%" border="1px" cellpadding=& ...
- [django]在virtualenv下安装的第三方库的使用方法
在virtualenv下安装的第三方库,例如south, requests等,如果想在django中使用,需要先将库添加到settings.py的INSTALLED_APPS中, 以south, re ...
- some tips learn from work experience
1.you can't avoid office politics 2.you'll never have a job which you "can't quit" - if yo ...