views:

1281

answers:

3

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 command over Stomp, messages sent with SEND are immediately published, and if I ABORT the transaction, nothing happens.

I can't find any clear answers suggesting that suggest it's not possible, that is 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?

+1  A: 

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.

James Strachan
Yeah, I'm following the Stomp protocol rules and sending a transaction header. (I wish I could get tcpflow working on this machine; tcpdump sucks for watching stomp.) I'll try that forum, too, thanks!
rjbs
+1  A: 

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.

huguei
A: 

You have to wrap the acknowledgements inside a transaction.

In pseudocode (or pseudo STOMP) this would be:

  • BEGIN [TRANSACTION-ID]
  • MESSAGE [MESSAGE-ID] (received)
  • ACK [MESSAGE-ID] [TRANSACTION-ID]
  • ABORT [TRANSACTION-ID]

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

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

Phillip Whelan