Ejemplo n.º 1
0
        public ReceiveResult TryReceiveFrom(TableBasedQueue queue)
        {
            MessageReadResult readResult;

            using (var connection = sqlConnectionFactory.OpenNewConnection(connectionString))
            {
                readResult = queue.TryReceive(connection);
                if (readResult.IsPoison)
                {
                    errorQueue.Send(readResult.DataRecord, connection);
                    return(ReceiveResult.NoMessage());
                }
            }

            if (!readResult.Successful)
            {
                return(ReceiveResult.NoMessage());
            }

            var result = ReceiveResult.Received(readResult.Message);

            try
            {
                tryProcessMessageCallback(readResult.Message);
                return(result);
            }
            catch (Exception ex)
            {
                return(result.FailedProcessing(ex));
            }
        }
        public ReceiveResult TryReceiveFrom(TableBasedQueue queue)
        {
            using (var connection = new SqlConnection(connectionString))
            {
                connection.Open();
                using (pipelineExecutor.SetConnection(connectionString, connection))
                {
                    using (var transaction = connection.BeginTransaction(isolationLevel))
                    {
                        using (pipelineExecutor.SetTransaction(connectionString, transaction))
                        {
                            MessageReadResult readResult;
                            try
                            {
                                readResult = queue.TryReceive(connection, transaction);
                            }
                            catch (Exception)
                            {
                                transaction.Rollback();
                                throw;
                            }

                            if (readResult.IsPoison)
                            {
                                errorQueue.Send(readResult.DataRecord, connection, transaction);
                                transaction.Commit();
                                return(ReceiveResult.NoMessage());
                            }

                            if (!readResult.Successful)
                            {
                                transaction.Commit();
                                return(ReceiveResult.NoMessage());
                            }

                            var result = ReceiveResult.Received(readResult.Message);
                            try
                            {
                                if (tryProcessMessageCallback(result.Message))
                                {
                                    transaction.Commit();
                                }
                                else
                                {
                                    transaction.Rollback();
                                }
                                return(result);
                            }
                            catch (Exception ex)
                            {
                                transaction.Rollback();
                                return(result.FailedProcessing(ex));
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public ReceiveResult TryReceiveFrom(TableBasedQueue queue)
        {
            using (var scope = new TransactionScope(TransactionScopeOption.Required, transactionOptions))
            {
                using (var connection = new SqlConnection(connectionString))
                {
                    connection.Open();
                    using (pipelineExecutor.SetConnection(connectionString, connection))
                    {
                        var readResult = queue.TryReceive(connection);
                        if (readResult.IsPoison)
                        {
                            errorQueue.Send(readResult.DataRecord, connection);
                            scope.Complete();
                            return(ReceiveResult.NoMessage());
                        }

                        if (!readResult.Successful)
                        {
                            scope.Complete();
                            return(ReceiveResult.NoMessage());
                        }

                        var result = ReceiveResult.Received(readResult.Message);

                        try
                        {
                            if (tryProcessMessageCallback(readResult.Message))
                            {
                                scope.Complete();
                                scope.Dispose(); // We explicitly calling Dispose so that we force any exception to not bubble, eg Concurrency/Deadlock exception.
                            }
                            return(result);
                        }
                        catch (Exception ex)
                        {
                            return(result.FailedProcessing(ex));
                        }
                    }
                }
            }
        }