Skip to content

Commit

Permalink
More refactoring for completing message handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ayende committed Apr 4, 2010
1 parent 3678508 commit 1fa2aa5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
5 changes: 4 additions & 1 deletion Rhino.ServiceBus/Msmq/MsmqTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,10 @@ private void ProcessMessage(
}
finally
{
var messageHandlingCompletion = new MessageHandlingCompletion(message, tx, messageQueue, ex, messageCompleted, beforeMessageTransactionCommit, logger, MessageProcessingFailure, currentMessageInformation);
Action sendMessageBackToQueue = null;
if (message != null && messageQueue.IsTransactional == false)
sendMessageBackToQueue = () => messageQueue.Send(message);
var messageHandlingCompletion = new MessageHandlingCompletion(tx, sendMessageBackToQueue, ex, messageCompleted, beforeMessageTransactionCommit, logger, MessageProcessingFailure, currentMessageInformation);
messageHandlingCompletion.HandleMessageCompletion();
currentMessageInformation = null;
}
Expand Down
20 changes: 6 additions & 14 deletions Rhino.ServiceBus/Transport/MessageHandlingCompletion.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
using System;
using System.Messaging;
using System.Transactions;
using log4net;
using Rhino.ServiceBus.Impl;

namespace Rhino.ServiceBus.Msmq
namespace Rhino.ServiceBus.Transport
{
public class MessageHandlingCompletion
{
private readonly Message message;
private readonly TransactionScope tx;
private readonly OpenedQueue messageQueue;
private readonly Action sendMessageBackToQueue;
private readonly Action<CurrentMessageInformation, Exception> messageCompleted;
private readonly Action<CurrentMessageInformation> beforeTransactionCommit;
private readonly ILog logger;
Expand All @@ -19,11 +17,10 @@ public class MessageHandlingCompletion

private Exception exception;

public MessageHandlingCompletion(Message message, TransactionScope tx, OpenedQueue messageQueue, Exception exception, Action<CurrentMessageInformation, Exception> messageCompleted, Action<CurrentMessageInformation> beforeTransactionCommit, ILog logger, Action<CurrentMessageInformation, Exception> messageProcessingFailure, CurrentMessageInformation currentMessageInformation)
public MessageHandlingCompletion(TransactionScope tx, Action sendMessageBackToQueue, Exception exception, Action<CurrentMessageInformation, Exception> messageCompleted, Action<CurrentMessageInformation> beforeTransactionCommit, ILog logger, Action<CurrentMessageInformation, Exception> messageProcessingFailure, CurrentMessageInformation currentMessageInformation)
{
this.message = message;
this.tx = tx;
this.messageQueue = messageQueue;
this.sendMessageBackToQueue = sendMessageBackToQueue;
this.exception = exception;
this.messageCompleted = messageCompleted;
this.beforeTransactionCommit = beforeTransactionCommit;
Expand Down Expand Up @@ -77,9 +74,6 @@ public void HandleMessageCompletion()
{
logger.Warn("Failed to dispose of transaction in error mode.", e);
}
if (message == null)
return;


try
{
Expand All @@ -102,10 +96,8 @@ public void HandleMessageCompletion()
moduleException);
}

if (messageQueue.IsTransactional == false)// put the item back in the queue
{
messageQueue.Send(message);
}
if (sendMessageBackToQueue != null)
sendMessageBackToQueue();
}

}
Expand Down

0 comments on commit 1fa2aa5

Please sign in to comment.