rabbitmq.“消费端确认收到”和“推送者确认”(1)

前序

  使用诸如rabbitmq一类的系统作为消息服务,实际中基本都是分布式系统。由于发送协议无法保证信息送达到伙伴的手里,也没法保证伙伴成功的处理这些消息。所以需要一种“确认机制”来确认传输和信息处理过程的状态。RabbitMQ的下的多个协议都有支持这个特性。本文基于AMQP 0-9-1进行介绍,但是理念也适用于其他类似的协议。

  在“订阅者/消费者”到RabbitMQ服务器的"传输成功与否确认"已知AMQP 0-9-1有涵盖。从broker(消息队列服务器)到consumers(消息发布者)是扩展协议,被称之为“Publisher Confirm.

        所有的功能都是收到TCP协议的启发。这是从publishers到RabbitMQ节点,RabbitMQ节点到consumers可靠运作的保证。

 

投递成功与否确认

    当 RabbitMQ 向消费端传送了一则消息,它需要什么情况下判定消息发送成功了。 什么样的处理的逻辑是最好的这依赖于系统。所以,这主要是一种应用决策。在AMQP 0-9-1,视为成功的条件是当消费端通过basic.consume方法注册,或者通过basic.get,消息被拉取得时候。所以投递标签的作用域是channel。

投递标识:投递标识标签

    在我们进入主题之前,我们先解释“投递”如何被标识(和确认各自的投资结果)。当有消费端(订阅者)注册的时候,RabbitMQ 将用basic.delivermethod函数将信息投递出去。这个函数携带一个“投递标签”,这个标签在一个channel上是唯一的。

    投递标签是客户端库提供的单调增长的整数。客户端确认投递结果的时候回携带一个标签参数。

    因为投递标签的作用域是channel,需要在获取消息的channel上确认投递结果。如果确认信息来自不同的channel则会报“位置标签”的协议信息并关闭channel。

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

原文:

Introduction

Systems that use a messaging broker such as RabbitMQ are bydefinition distributed. Since protocol methods (messages) sentare not guaranteed to reach the peer or be successfully processedby it, both publishers and consumers need a mechanism fordelivery and processing confirmation. Several messagingprotocols supported by RabbitMQ provide such features.This guide covers the features in AMQP 0-9-1 but the ideais largely the same in other protocols (STOMP, MQTT, et cetera).

Delivery processing acknowledgements from consumers to RabbitMQare known as acknowledgements in AMQP 0-9-1 parlance; brokeracknowledgements to publishers are a protocol extension calledpublisher confirms.

Both features build on the same idea and are inspired by TCP.They are essential for reliable delivery both from publishersto RabbitMQ nodes and from RabbitMQ nodes to consumers.

 

(Consumer) Delivery Acknowledgements

When RabbitMQ delivers a message to a consumer, it needs to know when to consider the message to be successfully sent. What kind of logic is optimal depends on the system. It is therefore primarily an application decision. In AMQP 0-9-1 it is made when a consumer is registered using the basic.consume method or a message is fetched on demand with the basic.get method.

If you prefer a more example-oriented and step-by-step material, consumer acknowledgements arealso covered in RabbitMQ tutorial #2.

Delivery Identifiers: Delivery Tags

Before we proceed to discuss other topics it is important toexplain how deliveries are identified (and acknowledgementsindicate their respective deliveries). When a consumer(subscription) is registered, messages will be delivered(pushed) by RabbitMQ using the basic.delivermethod. The method carries a delivery tag, whichuniquely identifies the delivery on a channel. Delivery tags aretherefore scoped per channel.

Delivery tags are monotonically growing positiveintegers and are presented as such by client libraries.Client library methods that acknowledge deliveries take a delivery tagas an argument.

Because delivery tags are scoped per channel, deliveries must beacknowledged on the same channel they were received on. Acknowledgingon a different channel will result in an "unknown delivery tag" protocolexception and close the channel.

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值