2
votes

I am trying to implement JMS for my present project.

I have created message producer and message consumer as two separate applications and want to have production and consumption as two separate processes(clients). But my requirement is to have transaction management between producer and consumer. Say if producer was sending batch of 100 messages and if any of a single message delivery fails, whole 100 massage batch should failed.

I guess I can achieve this, because my each batch of messages sent is in separate session, so I can commit or rollback the session. But my consumer is async and runs on single session.

How can I achieve transaction management in consumer ? I want consumer should also rollback above mentioned 100 message batch processing if any of the single message processing (consumption) from that batch fails.

1

1 Answers

4
votes

You like to achieve something like end-to-end acknowledgements, but this conflicts somehow with the idea of message queues which are asynchronous by nature. If your consumer is busy, the transaction would possibly span a longer period of time.

To simplify it, I would not send 100 messages, but only one message, because actually you only have one logical message.

To implement the acknowledgement/retry, the consumer could send back another message on a different queue. The producer can do retries, the receiver must discard duplicates etc.

I would rather split the duties: The producer's responsibility is to deliver to messages to your messaging server. It's the data center's resposibility to check for queue's filling up. And it's the client's responsibility, that only messages which are processed completely are removed from the queue (look for JMS session CLIENT_ACKNOWLEDGE).