我如何知道消息是否已传送到队列?

How can I know if the message was delivered to a queue?

我正在使用 stomp-client 库,我想知道是否可以知道消息是否已传送到队列。因为我实现了一个 java 服务来执行消息的出队和一个节点 js 来将消息发送到队列。下面的代码显示了我如何将消息发送到队列。

this._stompClient.publish('/queue/MessagesQueue', messageToPublish, { })

当您发送 SEND 帧(即发布消息)时,您可以添加 receipt header,然后当您从代理收到 RECEIPT 帧时你知道它已成功收到消息。 STOMP specification 关于 receipt header:

Any client frame other than CONNECT MAY specify a receipt header with an arbitrary value. This will cause the server to acknowledge receipt of the frame with a RECEIPT frame which contains the value of this header as the value of the receipt-id header in the RECEIPT frame.

但是,查看 stomp-client 的文档时,我没有看到任何关于如何接收 RECEIPT 帧的提及。我实际上希望能够在接收到 RECEIPT 帧时调用的 publish 方法上指定回调。 stomp-client 似乎不支持使用收据。不幸的是,这意味着没有真正的方法来确认消息已被代理收到。

我建议你找一个更成熟的支持收据的STOMP客户端实现。例如 stomp-js supports receipts.