-
Hi, I can't find a way to specify this mode when receiving a message, am I doing something wrong? Here is a small sample which shows how I receive a message
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
Hi @rizi, It basically means to use transactions for message acknowledgment. It is especially useful when you consume multiple messages, and you want to be sure that they will be acknowledged in all or nothing manner. Modifying slightly your example, it may look as follows: await using (IConnection connection = await connectionFactory.CreateAsync(endpoint))
{
IConsumer consumer = await connection.CreateConsumerAsync("Test", RoutingType.Anycast);
Message msg1 = await consumer.ReceiveAsync();
Message msg2 = await consumer.ReceiveAsync();
// start transaction
await using (var transaction = new Transaction())
{
// ack the first message
await consumer.AcceptAsync(msg1, transaction);
// ack the second message
await consumer.AcceptAsync(msg2, transaction);
// commit the transaction
await transaction.CommitAsync();
// at this point you're sure that both messages were acknowledged
}
} Of course, this is only a small example. You can do much more with transactions. For more use cases, please check out the transactions spec --> https://github.com/Havret/dotnet-activemq-artemis-client/blob/master/test/ActiveMQ.Artemis.Client.IntegrationTests/TransactionsSpec.cs I hope this answers your question. |
Beta Was this translation helpful? Give feedback.
-
Thx for the answer, that makes things much more clearer! Br |
Beta Was this translation helpful? Give feedback.
-
Hello! I thought that consumer.AcceptAsync says consumer that the message is processed properly and must be dequeued so it disappears from the queue. Thus if an exception is thrown between consumer.ReceiveAsync and consumer.AcceptAsync methods consumer would be able to get the same message again, because the message wasn't acknowledged. However message disappears from the queue right after consumer.ReceiveAsync method call. And after recovery I'm not able to receive unacknowledged message. Where is my mistake? |
Beta Was this translation helpful? Give feedback.
Hi @rizi,
It basically means to use transactions for message acknowledgment. It is especially useful when you consume multiple messages, and you want to be sure that they will be acknowledged in all or nothing manner.
Modifying slightly your example, it may look as follows: