Typically sends and acks are part of the transaction so if committing the transaction failed then I would also expect message.Acknowledge() to fail as well unless you start another transaction and receive the message again (which you're attempting to avoid).
It's worth noting that your code must always be prepared for a transaction to be rolled back since that is one of the two possible outcomes. If you're working with more than 1 resource manager (e.g. a database and a message broker) where work must be performed atomically you'd typically use an XA transaction. However, I don't believe the NMS client supports XA so that won't be an option for you. What you'll need to do instead is write your own code to maintain consistency. That could be as simple as making your message processing idempotent (e.g. using a database primary key) or implementing your own duplicate detection (e.g. based on the identity of the message which you store and check everytime a new message arrives). In any case, please send messages like this to the ActiveMQ users mailing list (i.e. us...@activemq.apache.org) instead of the dev list. The dev list is for folks working directly on an ActiveMQ code-base, not users who are developing messaging applications. This is noted on the website [1]. Thanks! Justin [1] https://activemq.apache.org/contact On Tue, Nov 12, 2024 at 8:35 AM Nitesh Soni <niti.son...@gmail.com> wrote: > Hi, > > In my .NET application, we use the Apache NMS DLL to consume ActiveMQ > messages with transactional commits. Occasionally, after processing a > message, session.commit() fails with TransactionRolledBackException. Since > the message is already processed, I want to prevent re-receiving it. Can I > call message.Acknowledge() if session.commit throws > TransactionRolledBackException to ensure the message is committed? > > Regards, > Nitesh >