[rabbitmq-discuss] Java client transaction with basic.consume
Matthias Radestock
matthias at lshift.net
Mon Apr 6 20:43:32 BST 2009
Tsuraan,
tsuraan wrote:
> My desired workflow is:
>
> basicConsume(...)
> forever() {
> consumer.nextDelivery()
> channel.txSelect()
> channel.basicAck(...)
> for(msg in some messages that depend on the delivered message) {
> channel.basicPublish(msg)
> }
> channel.txCommit()
> }
>
> My understanding (probably wrong) is that attempting to do blocking
> calls (like txSelect) on the channel being used by my consumer will
> cause a deadlock. The documentation for QueueingConsumer says that it
> has straightforward blocking semantics, but I'm not sure what that
> means. Is there a way to have my desired workflow using basicConsume,
> or do I need to do basicGet?
The above code should work with just a little bit of tweaking:
- call the basicConsume with a QueuingConsumer
- do the txSelect outside the loop - once a channel is in tx mode it
stays in it
Or, to put it another way, just take the code from
http://www.rabbitmq.com/api-guide.html#consuming
and add a channel.txSelect() outside the loop, and add the publishes and
a channel.txCommit() inside the loop.
Matthias.
More information about the rabbitmq-discuss
mailing list