void ITransport.ClearTimeout(string timeoutCorrelationID) { var transaction = openTransaction; // check for "ambient" transaction on current thread var commitAndDisposeTransaction = false; if (transaction == null) { transaction = BeginTransaction(); commitAndDisposeTransaction = true; } try { var conversationHandle = Guid.Parse(timeoutCorrelationID); if (PopTimeoutMessage(transaction, conversationHandle) != null) { ServiceBrokerWrapper.EndConversation(transaction, conversationHandle); } if (commitAndDisposeTransaction) { transaction.Commit(); } } finally { if (commitAndDisposeTransaction) { TryDisposeTransactionAndConnection(transaction); } } }
private void TryHandleMessage(SqlTransaction transaction, ServiceBrokerMessage message) { logger.Debug("Received message {0} from queue {1}", message.ConversationHandle, ServiceBrokerQueue); // NOTE this method _should not_ throw an exception! // It is responsible for committing or rolling back the SqlTransaction // that was passed in. // We can keep track of the openTransaction on the current thread in case we need it. openTransaction = transaction; try { // this may throw an exception if we need to rollback TryHandleMessageInner(transaction, message); // End the conversation and commit ServiceBrokerWrapper.EndConversation(transaction, message.ConversationHandle); transaction.Commit(); faultManager.ClearFailuresForMessage(message.ConversationHandle.ToString()); logger.Debug("Committed message {0} from queue {1}", message.ConversationHandle, ServiceBrokerQueue); } catch (Exception e) { TryRollbackTransaction(transaction); faultManager.IncrementFailuresForMessage(message.ConversationHandle.ToString(), e); logger.Error(e, "Exception caught handling message {0} from queue {1}. Rolling back transaction to retry.", message.ConversationHandle, ServiceBrokerQueue); #if DEBUG if (System.Diagnostics.Debugger.IsAttached) { System.Diagnostics.Debugger.Break(); } #endif } finally { openTransaction = null; TryDisposeTransactionAndConnection(transaction); // shoud not throw exception } }