async Task <OutboxMessage> StoreDispatchAndGetAsync() { var operations = new List <TransportOperation> { new TransportOperation( messageId: "Id1", options: new Dictionary <string, string> { { "OptionKey1", "OptionValue1" } }, body: new byte[] { 0x20, 0x21 }, headers: new Dictionary <string, string> { { "HeaderKey1", "HeaderValue1" } } ) }; var messageId = "a"; using (var connection = await dbConnection.OpenConnection().ConfigureAwait(false)) using (var transaction = connection.BeginTransaction()) { await persister.Store(new OutboxMessage(messageId, operations.ToArray()), transaction, connection).ConfigureAwait(false); transaction.Commit(); } await persister.SetAsDispatched(messageId, null).ConfigureAwait(false); return(await persister.Get(messageId, null).ConfigureAwait(false)); }
static async Task <OutboxMessage> StoreAndGetAsync(OutboxPersister persister, CancellationToken cancellationToken = default) { var operations = new[] { new TransportOperation( messageId: "Id1", properties: new DispatchProperties(new Dictionary <string, string> { { "OptionKey1", "OptionValue1" } }), body: new byte[] { 0x20, 0x21 }, headers: new Dictionary <string, string> { { "HeaderKey1", "HeaderValue1" } } ) }; var messageId = "a"; var contextBag = CreateContextBag(messageId); using (var transaction = await persister.BeginTransaction(contextBag, cancellationToken)) { await persister.Store(new OutboxMessage(messageId, operations), transaction, contextBag, cancellationToken).ConfigureAwait(false); await transaction.Commit(cancellationToken); } return(await persister.Get(messageId, contextBag, cancellationToken).ConfigureAwait(false)); }
async Task <OutboxMessage> StoreAndGetAsync(OutboxPersister persister) { var operations = new[] { new TransportOperation( messageId: "Id1", options: new Dictionary <string, string> { { "OptionKey1", "OptionValue1" } }, body: new byte[] { 0x20, 0x21 }, headers: new Dictionary <string, string> { { "HeaderKey1", "HeaderValue1" } } ) }; var messageId = "a"; using (var connection = await connectionManager.OpenNonContextualConnection().ConfigureAwait(false)) using (var transaction = connection.BeginTransaction()) { await persister.Store(new OutboxMessage(messageId, operations), transaction, connection).ConfigureAwait(false); transaction.Commit(); } return(await persister.Get(messageId, null).ConfigureAwait(false)); }
public async Task Should_get_messages() { var persister = new OutboxPersister(store, testEndpointName, CreateTestSessionOpener()); var messageId = Guid.NewGuid().ToString(); //manually store an OutboxRecord to control the OutboxRecordId format using (var session = OpenAsyncSession()) { var newRecord = new OutboxRecord { MessageId = messageId, Dispatched = false, TransportOperations = new[] { new OutboxRecord.OutboxOperation { Message = new byte[1024 * 5], Headers = new Dictionary <string, string>(), MessageId = messageId, Options = new Dictionary <string, string>() } } }; var fullDocumentId = "Outbox/TestEndpoint/" + messageId; await session.StoreAsync(newRecord, fullDocumentId); await session.SaveChangesAsync(); } var result = await persister.Get(messageId, new ContextBag()); Assert.NotNull(result); Assert.AreEqual(messageId, result.MessageId); }
async Task <Tuple <OutboxMessage, OutboxMessage> > StoreDispatchAndGetAsync(OutboxPersister persister) { var operations = new List <TransportOperation> { new TransportOperation( messageId: "Id1", options: new Dictionary <string, string> { { "OptionKey1", "OptionValue1" } }, body: new byte[] { 0x20, 0x21 }, headers: new Dictionary <string, string> { { "HeaderKey1", "HeaderValue1" } } ) }; var messageId = "a"; var contextBag = CreateContextBag(messageId); using (var transaction = await persister.BeginTransaction(contextBag)) { await persister.Store(new OutboxMessage(messageId, operations.ToArray()), transaction, contextBag).ConfigureAwait(false); await transaction.Commit(); } var beforeDispatch = await persister.Get(messageId, contextBag).ConfigureAwait(false); await persister.SetAsDispatched(messageId, contextBag).ConfigureAwait(false); var afterDispatch = await persister.Get(messageId, contextBag).ConfigureAwait(false); return(Tuple.Create(beforeDispatch, afterDispatch)); }
public async Task Should_save_with_not_dispatched() { var persister = new OutboxPersister(store, testEndpointName, CreateTestSessionOpener()); var id = Guid.NewGuid().ToString("N"); var message = new OutboxMessage(id, new[] { new TransportOperation(id, new Dictionary <string, string>(), new byte[1024 * 5], new Dictionary <string, string>()) }); using (var transaction = await persister.BeginTransaction(new ContextBag())) { await persister.Store(message, transaction, new ContextBag()); await transaction.Commit(); } var result = await persister.Get(id, new ContextBag()); var operation = result.TransportOperations.Single(); Assert.AreEqual(id, operation.MessageId); }
public async Task Should_filter_invalid_docid_character() { var persister = new OutboxPersister(store, testEndpointName, CreateTestSessionOpener()); var guid = Guid.NewGuid(); var messageId = $@"{guid}\12345"; var emptyDictionary = new Dictionary <string, string>(); var operation = new TransportOperation("test", emptyDictionary, new byte[0], emptyDictionary); var transportOperations = new [] { operation }; using (var transaction = await persister.BeginTransaction(new ContextBag())) { await persister.Store(new OutboxMessage(messageId, transportOperations), transaction, new ContextBag()); await transaction.Commit(); } var outboxMessage = await persister.Get(messageId, new ContextBag()); Assert.AreEqual(messageId, outboxMessage.MessageId); Assert.AreEqual(1, outboxMessage.TransportOperations.Length); Assert.AreEqual("test", outboxMessage.TransportOperations[0].MessageId); }