コード例 #1
0
        async Task <MessageReadResult> ReadMessage(SqlCommand command, CancellationToken cancellationToken)
        {
            var behavior = CommandBehavior.SingleRow;

            if (isStreamSupported)
            {
                behavior |= CommandBehavior.SequentialAccess;
            }

            using (var dataReader = await command.ExecuteReaderAsync(behavior, cancellationToken).ConfigureAwait(false))
            {
                if (!await dataReader.ReadAsync(cancellationToken).ConfigureAwait(false))
                {
                    return(MessageReadResult.NoMessage);
                }

                var readResult = await MessageRow.Read(dataReader, isStreamSupported, cancellationToken).ConfigureAwait(false);

                //HINT: Reading all pending results makes sure that any query execution error,
                //      sent after the first result, are thrown by the SqlDataReader as SqlExceptions.
                //      More details in: https://github.com/DapperLib/Dapper/issues/1210
                while (await dataReader.ReadAsync(cancellationToken).ConfigureAwait(false))
                {
                }

                while (await dataReader.NextResultAsync(cancellationToken).ConfigureAwait(false))
                {
                }

                return(readResult);
            }
        }
コード例 #2
0
        async Task SendRawMessage(MessageRow message, SqlConnection connection, SqlTransaction transaction, CancellationToken cancellationToken)
        {
            try
            {
                var sendCommand = await GetSendCommandText(connection, transaction, cancellationToken).ConfigureAwait(false);

                using (var command = new SqlCommand(sendCommand, connection, transaction))
                {
                    message.PrepareSendCommand(command);

                    await command.ExecuteNonQueryAsync(cancellationToken).ConfigureAwait(false);
                }
            }
            // 207 = Invalid column name
            // 515 = Cannot insert the value NULL into column; column does not allow nulls
            catch (SqlException ex) when((ex.Number == 207 || ex.Number == 515) && ex.Message.Contains("Recoverable"))
            {
                cachedSendCommand = null;
                throw new Exception($"Failed to send message to {qualifiedTableName} due to a change in the existence of the Recoverable column that is scheduled for removal. If the table schema has changed, this is expected. Retrying the message send will detect the new table structure and adapt to it.", ex);
            }
            catch (SqlException ex) when(ex.Number == 208)
            {
                ThrowQueueNotFoundException(ex);
            }
            catch (Exception ex) when(!ex.IsCausedBy(cancellationToken))
            {
                ThrowFailedToSendException(ex);
            }
        }
コード例 #3
0
        async Task SendRawMessage(MessageRow message, SqlConnection connection, SqlTransaction transaction)
        {
            try
            {
                using (var command = new SqlCommand(sendCommand, connection, transaction))
                {
                    message.PrepareSendCommand(command);

                    await command.ExecuteNonQueryAsync().ConfigureAwait(false);
                }
            }
            catch (SqlException ex)
            {
                if (ex.Number == 208)
                {
                    ThrowQueueNotFoundException(ex);
                }

                ThrowFailedToSendException(ex);
            }
            catch (Exception ex)
            {
                ThrowFailedToSendException(ex);
            }
        }
コード例 #4
0
        async Task <MessageReadResult> ReadMessage(SqlCommand command, CancellationToken cancellationToken)
        {
            var behavior = CommandBehavior.SingleRow;

            if (isStreamSupported)
            {
                behavior |= CommandBehavior.SequentialAccess;
            }

            using (var dataReader = await command.ExecuteReaderAsync(behavior, cancellationToken).ConfigureAwait(false))
            {
                if (!await dataReader.ReadAsync(cancellationToken).ConfigureAwait(false))
                {
                    return(MessageReadResult.NoMessage);
                }

                return(await MessageRow.Read(dataReader, isStreamSupported, cancellationToken).ConfigureAwait(false));
            }
        }
コード例 #5
0
        public Task Send(OutgoingMessage message, TimeSpan timeToBeReceived, SqlConnection connection, SqlTransaction transaction, CancellationToken cancellationToken = default)
        {
            var messageRow = MessageRow.From(message.Headers, message.Body, timeToBeReceived);

            return(SendRawMessage(messageRow, connection, transaction, cancellationToken));
        }
コード例 #6
0
 public Task DeadLetter(MessageRow poisonMessage, SqlConnection connection, SqlTransaction transaction, CancellationToken cancellationToken = default)
 {
     return(SendRawMessage(poisonMessage, connection, transaction, cancellationToken));
 }
コード例 #7
0
 public Task DeadLetter(MessageRow poisonMessage, SqlConnection connection, SqlTransaction transaction)
 {
     return(SendRawMessage(poisonMessage, connection, transaction));
 }