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概述的更多相关文章

  1. Spring Cloud 概述

    1. Spring Cloud 引言 首先我们打开spring 的官网:https://spring.io/ 我们会看到这样一张图片 这个图片告诉我们,开发我们的应用程序就像盖楼一样, 首先我们需要搭 ...

  2. Spring Rabbitmq HelloWorld实例

    之前的博客和大家分享了Rabbitmq的基本框架,及其工作原理,网址为 < http://www.cnblogs.com/jun-ma/p/4840869.html >.今天呢,想和大家一 ...

  3. Spring rabbitMq 中 correlationId或CorrelationIdString 消费者获取为null的问题

    问题 在用Spring boot 的 spring-boot-starter-amqp   快速启动 rabbitMq 是遇到了个坑 消费者端获取不到:correlationId或Correlatio ...

  4. Spring Integration概述

    1.   Spring Integration概述 1.1     背景 Spring框架的一个重要主题是控制反转.从广义上来说,Spring处理其上下文中管理的组件的职责.只要组件减轻了职责,它们同 ...

  5. (转)Spring的概述

    http://blog.csdn.net/yerenyuan_pku/article/details/69663685 Spring的概述 什么是Spring 据度娘所载: Spring是一个开源框架 ...

  6. 微服务与Spring Cloud概述

    微服务与Spring Cloud随着互联网的快速发展, 云计算近十年也得到蓬勃发展, 企业的IT环境和IT架构也逐渐在发生变革,从过去的单体应用架构发展为至今广泛流行的微服务架构. 微服务是一种架构风 ...

  7. Spring IOC 概述

    Spring IOC 概述 IOC(Inversion of Control) 控制反转,也叫 DI(D_ependency injection_) 依赖注入.是一种设计思想.不过我并不同意所谓反转的 ...

  8. RabbitMq 概述

    RabbitMQ是实现了高级消息队列协议(Advanced Message Queueing Protocol , AMQP)的开源消息代理软件(亦称面向消息的中间件). 1.AMQP协议 Rocke ...

  9. 1.Spring 框架概述

    目录 Spring 框架概述 1 我们所说的 "Spring "是什么意思 2. Spring和Spring框架的历史 3. 设计理念 4.反馈和贡献 5.开始使用 Spring ...

随机推荐

  1. PC和HOST之间文件传送

    从PC到HOST 文件传送表(*.srl) C:\123.txt text ~'LIANG.TEST.LIB.123' 批处理文件(*.bat) SEND "PC文件全路径" 'H ...

  2. 优化openfire服务器,达到单机20万,集群50万

    openfire压测概述 个月左右的测试,总算得到预定目标(3台服务器,并发50w用户在线) 测试环境搭建 压测客户端无他-tsung,尝试了windows安装perl失败后,使用centOS6.5作 ...

  3. break continue.

    1.break与continue.这两个关键字一般放在循环的花括号里面使用.break——结束整个循环.continue——结束本次循环,进入下次循环. 2.while循环 //初始条件 while( ...

  4. Sharepoint创建List

    (一)在一个环境下创建site 首先在sharepoint 2013 Central Administration中run administration --Application Managemen ...

  5. myeclipse性能优化

    1. 取消启动项.这个设置立竿见影.Window->Preferences->General->Startup and Shutdown, Plug-ins activated on ...

  6. 02-Swift初体验

    Playground是什么? 从Xcode6开始出现(Swift开始出现) 翻译为:操场/游乐场 对于学习Swift基本语法非常方便 所见即所得(快速查看结果) 语法特性发生改变时,可以快速查看. S ...

  7. C++面试中关于sizeof问题总结

    原文:http://blog.sina.com.cn/s/blog_7c983ca60100yfdv.html#SinaEditor_Temp_FontName (1)      sizeof是操作符 ...

  8. 五步搞定Android开发环境部署

    引言   在windows安装Android的开发环境不简单也说不上算复杂,本文写给第一次想在自己Windows上建立Android开发环境投入 Android浪潮的朋友们,为了确保大家能顺利完成开发 ...

  9. python模块及包的导入

    一.模块 通常模块为一个文件,直接使用import来导入就好了.可以作为module的文件类型有".py".".pyo".".pyc".&q ...

  10. UDP及其组播,接收发送封装

    1.Receiver public class Receiver { public delegate void HeartBeat(byte[] data); public event HeartBe ...