/// <inheritdoc /> public async Task <DelayedMessage> FetchNextDueTimeout(DateTimeOffset at, CancellationToken cancellationToken = default) { DelayedMessage result = null; using (var cn = await createSqlConnection(cancellationToken).ConfigureAwait(false)) using (var cmd = new SqlCommand(fetchCommand, cn)) { cmd.Parameters.AddWithValue("@time", at.UtcDateTime); await cn.OpenAsync(cancellationToken).ConfigureAwait(false); using (var reader = await cmd.ExecuteReaderAsync(CommandBehavior.SingleRow, cancellationToken).ConfigureAwait(false)) { if (await reader.ReadAsync(cancellationToken).ConfigureAwait(false)) { result = new DelayedMessage { MessageId = (string)reader[0], Destination = (string)reader[1], Time = (DateTime)reader[2], Headers = (byte[])reader[3], Body = (byte[])reader[4], NumberOfRetries = (int)reader[5] }; } } } return(result); }
/// <inheritdoc /> public async Task <bool> IncrementFailureCount(DelayedMessage timeout, CancellationToken cancellationToken = default) { using (var cn = await createSqlConnection(cancellationToken).ConfigureAwait(false)) using (var cmd = new SqlCommand(bumpFailureCountCommand, cn)) { cmd.Parameters.AddWithValue("@id", timeout.MessageId); await cn.OpenAsync(cancellationToken).ConfigureAwait(false); var affected = await cmd.ExecuteNonQueryAsync(cancellationToken).ConfigureAwait(false); return(affected == 1); } }
/// <inheritdoc /> public async Task Store(DelayedMessage timeout, CancellationToken cancellationToken = default) { using (var cn = await createSqlConnection(cancellationToken).ConfigureAwait(false)) using (var cmd = new SqlCommand(insertCommand, cn)) { cmd.Parameters.AddWithValue("@id", timeout.MessageId); cmd.Parameters.AddWithValue("@destination", timeout.Destination); cmd.Parameters.AddWithValue("@time", timeout.Time); cmd.Parameters.AddWithValue("@headers", timeout.Headers); cmd.Parameters.AddWithValue("@state", timeout.Body); await cn.OpenAsync(cancellationToken).ConfigureAwait(false); _ = await cmd.ExecuteNonQueryAsync(cancellationToken).ConfigureAwait(false); } }