如何通过 Stomp 和 ActiveMQ(和 Perl)使用事务?

发布于 2024-07-04 05:34:07 字数 334 浏览 7 评论 0原文

我正在尝试用 ActiveMQ 替换一些定制的消息队列,并且我需要通过 Perl 与它们进行(很多)对话。 ActiveMQ 提供了 Stomp 接口,而 Perl 有 Net::Stomp,所以这看起来应该没问题,但事实并非如此。

即使我通过 Stomp 发送 BEGIN 帧,使用 SEND 发送的消息也会立即发布,如果我 ABORT 事务也不会发生。

我找不到任何明确的答案表明这是不可能的,这是可能的,或者有一些相关的配置。 另外,Stomp 似乎并不是一个很好的检查服务器错误响应的协议。

我运气不好吗?

I'm trying to replace some bespoke message queues with ActiveMQ, and I need to talk to them (a lot) from Perl. ActiveMQ provides a Stomp interface and Perl has Net::Stomp, so this seems like it should be fine, but it's not.

Even if I send a BEGIN frame over Stomp the messages sent with SEND are immediately published, and if I ABORT the transaction nothing happens.

I can't find any clear answers suggesting that it's not possible, that it is possible, or that there's a relevant bit of configuration. Also, Stomp doesn't seem to be a great protocol for checking for error responses from the server.

Am I out of luck?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

究竟谁懂我的在乎 2024-07-11 05:34:07

您必须将确认包装在事务中。

在伪代码(或伪 STOMP)中,这将是:

  • BEGIN [TRANSACTION-ID] -> 发送到服务器
  • MESSAGE [MESSAGE-ID](已接收)<-从服务器接收到
  • ACK [MESSAGE-ID][TRANSACTION-ID]-> 发送到服务器
  • COMMIT [TRANSACTION-ID] -> 发送到服务器

我已经使用 PHP 驱动程序完成了此操作(当我传入框架对象进行确认时,修补中止调用以使用事务 ID)。

不幸的是,在重新发送四条消息后,客户端停止了。 至少这发生在我身上。

You have to wrap the acknowledgements inside a transaction.

In pseudocode (or pseudo STOMP) this would be:

  • BEGIN [TRANSACTION-ID] -> send to server
  • MESSAGE [MESSAGE-ID] (received) <- received from server
  • ACK [MESSAGE-ID] [TRANSACTION-ID] -> send to server
  • COMMIT [TRANSACTION-ID] -> send to server

I have already gotten this working with the PHP driver (patching the abort call to use the transaction ID when I pass in a frame object to acknowledge).

Unfortunately, after redelivering four messages the client stops. At least this happens to me.

困倦 2024-07-11 05:34:07

看看 Net:: Stomp::收据。 它是 Net::Stomp 的子类,用于实现 Stomp 协议的“回执”,并允许您确保消息的正确接收,否则中止事务。

Have a look at Net::Stomp::Receipt. It's a subclass of Net::Stomp that implements "return receipts" from the Stomp protocol, and allow you to make sure the correct reception of your message, and abort the transaction otherwise.

¢好甜 2024-07-11 05:34:07

顺便说一句,询问 Perl/ActiveMQ/Stomp 问题的最佳地点是 ActiveMQ 用户论坛很多 Perl-Stomp 爱好者都在那里闲逛。

STOMP 交易的技巧是确保您发送的每条消息或您做出的每个确认都包含交易 ID 标头。 请参阅STOMP 协议的事务处理部分

原因是,使用 STOMP,如果您的客户端是多线程的,则可能会同时发生许多事务 - 以及一些非事务性操作。

BTW the best place to ask Perl/ActiveMQ/Stomp questions is the ActiveMQ user forum as lots of Perl-Stomp folks hang out there.

The trick with STOMP transactions is to make sure each message you send or each acknowledgement you make includes the transaction ID header. See the transaction handling section of the STOMP protocol.

The reason for this is that with STOMP you could have many transactions taking place at the same time if your client is multi threaded - along with some non-transacted operations.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文