This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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