Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void HandleMessageCompletion(
- Message message,
- TransactionScope tx,
- OpenedQueue messageQueue,
- Exception exception,
- Action<CurrentMessageInformation, Exception> messageCompleted,
- Action<CurrentMessageInformation> beforeTransactionCommit)
- {
- beforeTransactionCommit = beforeTransactionCommit ?? (_ => { });
- var transaction = new TxWrapper(tx, logger);
- try
- {
- HandleErrors(message, messageQueue, exception, messageCompleted);
- HandleTransaction(beforeTransactionCommit, transaction);
- RaiseEventSafely(messageCompleted, currentMessageInformation, null);
- }
- catch (Exception ex)
- {
- HandleErrors(message, messageQueue, ex, messageCompleted);
- }
- }
- private void HandleTransaction(Action<CurrentMessageInformation> beforeTransactionCommit, TxWrapper transaction)
- {
- try
- {
- beforeTransactionCommit(currentMessageInformation);
- transaction.Complete();
- }
- finally
- {
- transaction.Dispose();
- }
- }
- private void HandleErrors(Message message, OpenedQueue messageQueue, Exception ex, Action<CurrentMessageInformation, Exception> messageCompleted)
- {
- if (ex == null)
- return;
- logger.Warn("Error mode", ex);
- if (message == null)
- return;
- RaiseEventSafely(messageCompleted, currentMessageInformation, ex);
- RaiseEventSafely(MessageProcessingFailure, currentMessageInformation, ex);
- if (messageQueue.IsTransactional == false) // put the item back in the queue
- {
- messageQueue.Send(message);
- }
- }
- private void RaiseEventSafely<T1, T2>(Action<T1, T2> @event, T1 arg1, T2 arg2)
- {
- try
- {
- if (@event != null)
- @event(arg1, arg2);
- }
- catch (Exception e)
- {
- logger.Error(
- "An error occured when raising an event, the error will NOT affect the message processing",
- e);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement