简体   繁体   English

当消息放入 MQ(消息队列)时,生产者是否等待 MQ 管理器的 ACK?

[英]When a message is put in a MQ (Message Queue) does the producer wait for ACK from the MQ Manager?

What I know is that Queues are used for asynchronous processing but I am wondering if the producer waits for an ACK from the MQ Manager to know that the message has been successfully put in the Message Queue, I am asking this because I have seen several sequence diagrams in my company where a Producer puts a message into a Message Queue and as a return it gets an ACK.我所知道的是队列用于异步处理,但我想知道生产者是否等待来自 MQ 管理器的 ACK 来知道消息已成功放入消息队列,我问这个是因为我看到了几个序列在我公司的图表中,生产者将一条消息放入消息队列,作为返回,它得到一个 ACK。 But if it waits for ACK wouldn't it turn it into a synchronous process instead of asynchronous?但是如果它等待ACK,它会不会把它变成一个同步过程而不是异步过程?

The exact behavior here would depend on the specific client implementation.此处的确切行为取决于特定的客户端实现。 That said, JMS allows both persistent and non-persistent messages and those will generally be sent blocking/synchronous and non-blocking/asynchronous respectively.也就是说,JMS 允许持久性和非持久性消息,这些消息通常分别以阻塞/同步和非阻塞/异步方式发送。

To be clear, persistent messages are those which should be written to durable storage (eg disk) by the broker so that in the event the broker shuts down or crashes the message will survive and be reloaded when the broker restarts.需要明确的是,持久消息是那些应该由代理写入持久存储(例如磁盘)的消息,以便在代理关闭或崩溃的情况下消息将继续存在并在代理重新启动时重新加载。 The idea is that persistent messages are therefore important enough that sending them should wait for a response from the broker to ensure the message arrived at the broker safely as expected.这个想法是持久消息因此非常重要,发送它们应该等待代理的响应以确保消息按预期安全到达代理。 Generally speaking this usually isn't referred to as an "ACK."一般来说,这通常称为“ACK”。 That terms usually denotes what happens when a client consumes and message and then tells the broker it is safe to remove the message from its memory/storage.该术语通常表示当客户端消费和消息时发生的事情,然后告诉代理可以安全地从其内存/存储中删除消息。

When folks talk about "asynchronous messaging" they aren't talking about the specific blocking semantics for sending a message.当人们谈论“异步消息传递”时,他们并不是在谈论发送消息的特定阻塞语义。 They are talking about the fact that producers are 100% disconnected from consumers.他们谈论的是生产者 100% 与消费者脱节的事实。 In other words, when a producer sends a message to a destination it doesn't care how quickly a consumer might receive that message or if there are any consumers at all.换句话说,当生产者向目的地发送消息时,它不关心消费者接收该消息的速度有多快,或者是否有任何消费者。 It simply sends the message.它只是发送消息。 Likewise, a consumer listens for messages with no regard for how the producers operate or indeed if there are any producers at all.同样,消费者收听消息时不考虑生产者的运作方式或者是否有任何生产者。 It simply receives and acknowledges messages, and it's important to note that this acknowledgement process is only between the consumer and the broker.它只是接收和确认消息,重要的是要注意这个确认过程只发生在消费者和代理之间。 The producer is not involved in that at all.生产者根本不参与其中。

In short, just because pieces of the component processes involve blocking operations doesn't mean that the process as a whole isn't asynchronous.简而言之,仅仅因为部分组件进程涉及阻塞操作并不意味着整个进程不是异步的。

Operations between clients and any MQ broker are strictly synchronous in a down-to-wire diagram.客户端和任何 MQ 代理之间的操作在下到线图中是严格同步的。 Under microscope view MQ messaging is always state machine implemented using direct calls between server and client, no matter which protocol is used.在显微镜下,无论使用哪种协议,MQ 消息传递始终是使用服务器和客户端之间的直接调用实现的状态机。 So, your ACK packets will be sent synchronously in a request reply coordination of calls between client and broker.因此,您的 ACK 数据包将在客户端和代理之间调用的请求回复协调中同步发送。 There is no such thing as asynchronous messaging on wire level.没有在线级别的异步消息传递之类的东西。

However, the very same process is asynchronous from a bird eye view of architecture of system.然而,从系统架构的鸟瞰图来看,同样的过程是异步的。 Goal of messaging is not to speak to a broker but to a message receiver.消息传递的目标不是与代理对话,而是与消息接收者对话。 From this perspective sending of a message is separated operation from consuming a message.从这个角度来看,发送消息是与使用消息分开的操作。 By using broker producers of messages do not talk directly to consumers and that is why it is called asynchronous.通过使用代理,消息生产者不会直接与消费者对话,这就是它被称为异步的原因。

Without message brokers, producers and consumers have to be directly wired.没有消息代理,生产者和消费者必须直接连线。 Any operation initiated by producer is directly mirrored on consumer side.生产者发起的任何操作都直接镜像到消费者端。 Synchronous calls, like REST, are thus close coupled.因此,同步调用(如 REST)是紧耦合的。 Downtime of any entity is also downtime of all system.任何实体的停机时间也是所有系统的停机时间。 MQ-ing is breaker of this close coupling and lets both entities to do job at their pace. MQ-ing 打破了这种紧密耦合,让两个实体按照自己的节奏完成工作。

Within JMS api itself there is other definition of synchronous and asynchronous calls.在 JMS api 本身中有同步和异步调用的其他定义。 Do not confuse it with synchronous and asynchronous messaging.不要将它与同步和异步消息传递混淆。 All JMS/MQ-ing is asynchronous from architecture view.从体系结构的角度来看,所有 JMS/MQ-ing 都是异步的。 But JMS lets the programmer to use two threading models: blocking thread model (synchronous one) and callback based model (asynchronous one).但是 JMS 允许程序员使用两种线程模型:阻塞线程模型(同步模型)和基于回调的模型(异步模型)。 This is sync/async thread control, and not sync/async messaging.这是同步/异步线程控制,而不是同步/异步消息传递。 Messaging using JMS is always asynchronous.使用 JMS 的消息传递始终是异步的。

The guy who named "blocking calls" as "synchronous" and "callback calls" as "asynchronous" within api intended for asynchronous messaging deserves to be shot.在用于异步消息传递的 api 中将“阻塞调用”命名为“同步”并将“回调调用”命名为“异步”的人应该被枪毙。 Plain stupidity.纯粹的愚蠢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM