RabbitMQ

rabbitmq系列(四)死信队列

こ雲淡風輕ζ 提交于 2020-03-23 09:53:16
一、什么是死信队列 当消息在一个队列中变成一个死信之后,它将被重新publish到另一个交换机上,这个交换机我们就叫做死信交换机,私信交换机将死信投递到一个队列上就是死信队列。具体原理如下图: 消息变成死信的三种情况: 消息被拒绝(basic.reject / basic.nack),并且requeue = false 消息TTL过期 队列达到最大长度 二、手动签收应答模式 应答模式分为两种,手动签收和自动签收,自动应答就是消费者消费了一条消息就自动告诉队列删除消息。这样的弊端就是不管消费逻辑有没有成功,都会将消息删除,这样就会造成消息丢失。而使用手动签收后,就是在消费逻辑处理成功后,手动告诉队列消费成功,然后队列再去删除这条消息。 再消费者配置文件中开启手动签收模式 spring.rabbitmq.listener.simple.acknowledge-mode = manual 在消费逻辑处理成功后手动签收,修改消费者代码 @RabbitListener(queues = QUEUE_NAME) public void receiveMessage(Message message,@Headers Map<String,Object> headers, Channel channel) throws Exception { Jedis jedis = new Jedis(

rabbitmq系列(四)死信队列

吃可爱长大的小学妹 提交于 2020-03-23 09:26:18
3 月,跳不动了?>>> 一、什么是死信队列 当消息在一个队列中变成一个死信之后,它将被重新publish到另一个交换机上,这个交换机我们就叫做死信交换机,私信交换机将死信投递到一个队列上就是死信队列。具体原理如下图: 消息变成死信的三种情况: 消息被拒绝(basic.reject / basic.nack),并且requeue = false 消息TTL过期 队列达到最大长度 二、手动签收应答模式 应答模式分为两种,手动签收和自动签收,自动应答就是消费者消费了一条消息就自动告诉队列删除消息。这样的弊端就是不管消费逻辑有没有成功,都会将消息删除,这样就会造成消息丢失。而使用手动签收后,就是在消费逻辑处理成功后,手动告诉队列消费成功,然后队列再去删除这条消息。 再消费者配置文件中开启手动签收模式 spring.rabbitmq.listener.simple.acknowledge-mode = manual 在消费逻辑处理成功后手动签收,修改消费者代码 @RabbitListener(queues = QUEUE_NAME) public void receiveMessage(Message message,@Headers Map<String,Object> headers, Channel channel) throws Exception { Jedis jedis =

RabbitMQ - How to Dead-letter / Process Messages in Expired Queues?

末鹿安然 提交于 2020-03-23 09:00:49
问题 I have an a queue that has x-expires set. The issue I am having is that I need to do further processing on the messages that are in the queue IF the queue expires. My initial idea was to set x-dead-letter-exchange on the queue. But, when the queue expires, the messages just vanish without making it to the dead-letter exchange. How can I dead-letter, or otherwise process, messages that are in a queue that expires? 回答1: As suggested in the comments, you cannot do this by relying only on the x

RabbitMq(7)消息延时推送

做~自己de王妃 提交于 2020-03-23 08:41:57
应用场景 目前常见的应用软件都有消息的延迟推送的影子,应用也极为广泛,例如: 淘宝七天自动确认收货。在我们签收商品后,物流系统会在七天后延时发送一个消息给支付系统,通知支付系统将款打给商家,这个过程持续七天,就是使用了消息中间件的延迟推送功能。 12306 购票支付确认页面。我们在选好票点击确定跳转的页面中往往都会有倒计时,代表着 30 分钟内订单不确认的话将会自动取消订单。其实在下订单那一刻开始购票业务系统就会发送一个延时消息给订单系统,延时30分钟,告诉订单系统订单未完成,如果我们在30分钟内完成了订单,则可以通过逻辑代码判断来忽略掉收到的消息。 在上面两种场景中,如果我们使用下面两种传统解决方案无疑大大降低了系统的整体性能和吞吐量: 使用 redis 给订单设置过期时间,最后通过判断 redis 中是否还有该订单来决定订单是否已经完成。这种解决方案相较于消息的延迟推送性能较低,因为我们知道 redis 都是存储于内存中,我们遇到恶意下单或者刷单的将会给内存带来巨大压力。 使用传统的数据库轮询来判断数据库表中订单的状态,这无疑增加了IO次数,性能极低。 使用 jvm 原生的 DelayQueue ,也是大量占用内存,而且没有持久化策略,系统宕机或者重启都会丢失订单信息。 消息延时推送实现 在 RabbitMQ 3.6.x 之前我们一般采用死信队列+TTL过期时间来实现延迟队列。

how to implement Remote procedure call (RPC) in RabbitMQ using Nodejs

谁都会走 提交于 2020-03-22 10:26:02
问题 so i want to take a Json and parse it to Object and then implement a RPC RabbitMQ Server so that i can send the Object to the Server through RabbitMQ and there the Object will be proceed to be saved in a local Array and a universally unique id which will tell where exactly is the object stored, will be returned from that Server to the client throught the RPC. the Official Webseite shows some Implementation to RPC in RabbitMQ, here you can find their Implementration https://www.rabbitmq.com

how to implement Remote procedure call (RPC) in RabbitMQ using Nodejs

时间秒杀一切 提交于 2020-03-22 10:25:28
问题 so i want to take a Json and parse it to Object and then implement a RPC RabbitMQ Server so that i can send the Object to the Server through RabbitMQ and there the Object will be proceed to be saved in a local Array and a universally unique id which will tell where exactly is the object stored, will be returned from that Server to the client throught the RPC. the Official Webseite shows some Implementation to RPC in RabbitMQ, here you can find their Implementration https://www.rabbitmq.com

php扩展AMQP,安装报错解决

本小妞迷上赌 提交于 2020-03-22 05:36:17
接下来来安装php扩展AMQP,安装了它以后,才能用PHP操作rabbitmq。 wget https://pecl.php.net/get/amqp-1.4.0.tgz tar -zxvf amqp-1.4.0.tgz cd amqp-1.4.0 /lnmp/php/bin/phpize ./configure --with-php-config=/lnmp/php/bin/php-config 安装到这,就报了错: checking for amqp files in default path… not found configure: error: Please reinstall the librabbit-mq distribution 在网上搜了搜,找到了解决方法(http://www.cnphp6.com/archives/68356): 需要安装rabbitmq-c,rabbitmq-c是一个用于C语言的,与AMQP server进行交互的client库。 下载地址:https://github.com/alanxz/rabbitmq-c unzip rabbitmq-c-master.zip cd rabbitmq-c-master autoreconf -i ./configure --prefix=/lnmp/rabbitmq-c make make

Spring集成RabbitMQ-必须知道的几个概念

主宰稳场 提交于 2020-03-22 00:58:14
上篇《Spring集成RabbiMQ-Spring AMQP新特性》我们了解了最新spring-rabbit的2.0.0.M5版本相较于之前有哪些变化。其实使用Spring-amqp确实简单,其主要就一些jar包,比如spring-amqp,spring-rabbit等。这篇就通过几个基本概念来了解下Spring amqp和原生amqp在用法上有何不同。 消息体 在《RabbitMQ入门》系列中,我们如果要发送一条消息,都是转成字节数组的,类似这样 channel.basicPublish("", QUEUE_NAME, null, "hello world".getBytes()); 但是在spring-amqp中,定义了一个消息类,用于存储消息实体和消息的属性信息。下面是该类的成员变量和方法 getBody就是获取消息体的内容,相当于上面的“hello world” getMessageProperties可以得到有关消息本身的属性信息,比如messageId消息的id标识,timestamp时间戳等等的值 使用这将上面属性的值通过setHeader(String key, Object value)方法添加到消息类中 Exchange 读过《RabbitMQ入门》系列,想必对于Exchange应该就不会陌生。在RabbitMQ是实际上所有的消息都不是生产者直接送到消费者

RabbitMQ入门-Routing直连模式

此生再无相见时 提交于 2020-03-22 00:56:17
Hello World模式,告诉我们如何一对一发送和接收消息; Work模式,告诉我们如何多管齐下高效的消费消息; Publish/Subscribe模式,告诉我们如何广播消息 那么有没有灵活强一点的既可以高效消费,又可以同时送达多个消费者的模式? 有,这就是Routing模式,我又称之为Direct直连模式。 Routing模式 一个生产者P,一个交换机X,多个消息队列Q以及多个消费者C 在Exchange和Queue中,我们看到了不同的规则,也就是Routing Key 显然从图中的说明,我们就知道这是一个log日志根据级别派发消息的例子。熟悉Log日志系统的应该都知道,一般的log系统分为error、info、warn和debug等。从图中我们可以看出,将日志级别为error的定向的派发到第一个消息队列,将error、warn和info级别的日志派发到第一个消息队列。 该模型首先实现了定向派发,而不再是订阅模式那种广播式的派发。同一条消息既可以派发给一个Queue,也可以同时派发给两个或者多个Queue,这就是该模式的灵活之处。下面来看看实例 发送端 /** * Created by jackie on 17/8/7. */ public class EmitLogDirect { private static final String EXCHANGE_NAME =

RabbitMQ学习第一记:用java连接RabbitMQ

 ̄綄美尐妖づ 提交于 2020-03-22 00:56:01
1、什么是RabbitMQ    MQ(Message Queue):消息队列,是服务端设计的一个可以存储大量消息的队列,并提供客户端操作队列的方法:生产队列(向队列中添加数据)、消费队列(从队列中取数据)。RabbitMQ就是基于消息队列的一个典型应用。RabbitMQ除了普通的生产消费功能,还有一些高级功能:公平分发 ,轮询分发,路 由模式,通配符模式,发布订阅,队列持久化。 2、java实现 RabbitMQ的连接 2.1、RabbitMQ客户端jar包 <dependency> <groupId>com.rabbitmq</groupId> <artifactId>amqp-client</artifactId> <version>4.0.2</version> </dependency> 2.2、java连接RabbitMQ工具类 public class ConnectionUtil { private static Logger logger = Logger.getLogger(ConnectionUtil.class); public static Connection getConnection() { try { Connection connection = null; //定义一个连接工厂 ConnectionFactory factory = new