public Sender(Func <CancellationToken, Task <DbConnection> > connectionFunc, HeadersBuilder headersBuilder, Table attachmentsTable, Table dedupeTable, ILogger logger) { this.connectionFunc = connectionFunc; attachments = new Persister(new NServiceBus.Attachments.Sql.Raw.Table(attachmentsTable.TableName, attachmentsTable.Schema, false)); this.headersBuilder = headersBuilder; this.dedupeTable = dedupeTable; this.logger = logger; }
public Sender(Func <CancellationToken, Task <SqlConnection> > connectionFunc, HeadersBuilder headersBuilder, Table attachmentsTable, Table dedupeTable, ILogger logger) { this.connectionFunc = connectionFunc; attachments = new(new(attachmentsTable.TableName, attachmentsTable.Schema, false)); this.headersBuilder = headersBuilder; this.dedupeTable = dedupeTable; this.logger = logger; }
public async Task <long> Send(PassthroughMessage message, Table destination, CancellationToken cancellation) { try { return(await InnerSend(message, destination, cancellation)); } catch (Exception exception) { throw new SendFailureException(message, exception); } }
async Task <long> InnerSend(PassthroughMessage message, Table destination, CancellationToken cancellation) { await using var connection = await connectionFunc(cancellation); await using var transaction = connection.BeginTransaction(); var rowVersion = await SendInsideTransaction(message, destination, cancellation, transaction); await transaction.CommitAsync(cancellation); return(rowVersion); }
async Task <long> SendInsideTransaction(PassthroughMessage message, Table destination, CancellationToken cancellation, DbTransaction transaction) { var headersString = headersBuilder.GetHeadersString(message); LogSend(message); var outgoingMessage = new OutgoingMessage( message.Id, headers: headersString, bodyBytes: Encoding.UTF8.GetBytes(message.Body)); var queueManager = new QueueManager(destination, transaction, dedupeTable); var attachmentExpiry = DateTime.UtcNow.AddDays(10); await SendAttachments(transaction, attachmentExpiry, cancellation, message); return(await queueManager.Send(outgoingMessage, cancellation)); }