使用 STOMP 连接 RabbitMQ 时如何重播丢失的消息? [英] How do you replay missed messages when using STOMP to connect to RabbitMQ?

查看:65
本文介绍了使用 STOMP 连接 RabbitMQ 时如何重播丢失的消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 iOS 应用程序,它使用 STOMP 客户端RabbitMQ.应用程序在启动期间加载大量状态,然后通过接收在 STOMP 上发布的更新来保持该状态同步.当然,如果它失去连接,它就不能再确定它是同步的,因此必须重新加载那个大的初始 blob.任何类型的网络中断都会触发这种行为并让我的客户感到难过.

I've got an iOS application which uses a STOMP Client to talk to RabbitMQ. The application loads a lot of state during startup, and then keeps that state in sync by receiving updates published on STOMP. Of course, if it loses its connection, it can no longer be sure it's in sync, and therefore has to re-load that large initial blob. Any kind of network interruption triggers this behavior and makes my customers sad.

有很多大局的方法可以解决这个问题(我正在研究它们),但与此同时,我正在尝试使用持久队列来解决这个问题.这个想法是服务器将创建一个队列,将其绑定到适当的主题,然后开始构建大型启动包.完成后,它将把一切交给客户.客户端将使用启动包设置自己,打开队列订阅,然后处理服务器准备就绪时发生的任何更新.同样,如果客户端断开连接,它可以简单地重新连接并继续读取它在队列中找到的消息.

There are a lot of big-picture ways to fix this (and I'm working on them) but in the meantime, I'm trying to use persistent queues to solve this problem. The idea is that the server will create a queue, bind it to the appropriate topics, and then start building the large startup bundle. When finished, it will hand everything off to the client. The client will set itself up with the startup bundle, open a subscription to the queue, and then process any updates which happened while the server was getting things ready. Similarly, if the client should become disconnected, it can simply reconnect and resume reading the messages it finds in the queue.

我的问题是,虽然客户端在连接后成功接收到发送的消息,但如果在连接之前队列中有任何消息,它们不会被读取.同样,如果客户端断开连接,当它重新连接时,它不会看到任何在它离开时到达的消息.

My problem is that while the client successfully receives messages sent after it connects, if there were any messages in the queue before it connected, they are not read. Likewise, if the client becomes disconnected, when it reconnects, it won't see any messages which arrived while it was away.

谁能建议我如何让客户能够阅读那些丢失的消息?

Can anyone suggest how I might get the client to be able to read those missing messages?

推荐答案

事实证明,STOMP 适配器正在使用消息,但未能传递消息.因此,当客户端重新连接时,它不会有任何消息等待它.

It turns out what was happening was that the STOMP adapter was consuming the messages but failing to deliver them. Thus, when the client reconnected, it wouldn't have any messages waiting for it.

为了解决这个问题,我将订阅请求上的ack"设置更改为client",这意味着 STOMP 在客户端发回 ACK 帧之前不应考虑消息已传递.通过适当地更改我的客户端,现在即使在客户端离开后也能传递消息.

To fix the problem, I changed the "ack" setting on the subscribe request to "client", meaning that STOMP shouldn't consider the message delivered until the client sends back an ACK frame. By changing my client appropriately, messages now get delivered even after the client has been away.

这篇关于使用 STOMP 连接 RabbitMQ 时如何重播丢失的消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆