Skip to content

Instantly share code, notes, and snippets.

@explorer14
Created Nov 21, 2021
Embed
What would you like to do?
public async Task ProcessMessages()
{
var message = default(AcknowledgeableMessage)
try
{
var message = await GetMessage();
// process the message here
message.Acknowledge(); //a.k.a. transaction.Commit()
}
catch(Exception ex)
{
message.Abandon();
}
}
public class AcknowledgeableMessage
{
private IDbTransaction _transaction;
public string Id {get;}
//...other properties
public AcknowledgeableMessage(IDbTransaction transaction, string messageId,...)
{
_transaction = transaction;
Id = messageId;
// map other properties
}
public void Acknowledge()
{
_transaction?.Commit();
}
public void Abandon()
{
_transaction?.Rollback();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment