public bool TryGet(string messageId, out OutboxMessage message) { using (new TransactionScope(TransactionScopeOption.Suppress)) { OutboxRecord result; message = null; using (var session = SessionFactoryProvider.SessionFactory.OpenStatelessSession()) { using (var tx = session.BeginTransaction(IsolationLevel.ReadCommitted)) { //Explicitly using ICriteria instead of QueryOver for performance reasons. //It seems QueryOver uses quite a bit reflection and that takes longer. result = session.CreateCriteria<OutboxRecord>().Add(Expression.Eq("MessageId", messageId)) .UniqueResult<OutboxRecord>(); tx.Commit(); } } if (result == null) { return false; } message = new OutboxMessage(result.MessageId); var operations = ConvertStringToObject(result.TransportOperations); message.TransportOperations.AddRange(operations.Select(t => new TransportOperation(t.MessageId, t.Options, t.Message, t.Headers))); return true; } }
public bool TryGet(string messageId, out OutboxMessage message) { OutboxRecord result; using (var session = DocumentStore.OpenSession()) { session.Advanced.AllowNonAuthoritativeInformation = false; // We use Load operation and not queries to avoid stale results result = session.Load<OutboxRecord>(new[] { GetOutboxRecordId(messageId), GetOutboxRecordIdWithoutEndpointName(messageId) }).FirstOrDefault(o => o != null); } if (result == null) { message = null; return false; } message = new OutboxMessage(result.MessageId); if (!result.Dispatched) { message.TransportOperations.AddRange( result.TransportOperations.Select(t => new TransportOperation(t.MessageId, t.Options, t.Message, t.Headers)) ); } return true; }
public Task Store(OutboxMessage message, OutboxTransaction transaction, ContextBag context) { StupidTransaction tx = (StupidTransaction)transaction; tx.Message = message; return(Task.FromResult(0)); }
public Task Store(OutboxMessage message, OutboxTransaction transaction, ContextBag context) { var session = ((RavenDBOutboxTransaction)transaction).AsyncSession; var operations = new OutboxRecord.OutboxOperation[message.TransportOperations.Length]; var index = 0; foreach (var transportOperation in message.TransportOperations) { operations[index] = new OutboxRecord.OutboxOperation { Message = transportOperation.Body, Headers = transportOperation.Headers, MessageId = transportOperation.MessageId, Options = transportOperation.Options }; index++; } return session.StoreAsync(new OutboxRecord { MessageId = message.MessageId, Dispatched = false, TransportOperations = operations }, GetOutboxRecordId(message.MessageId)); }
public bool TryGet(string messageId, out OutboxMessage message) { StoredMessage storedMessage; message = null; if (!storage.TryGetValue(messageId, out storedMessage)) { return false; } message = new OutboxMessage(messageId); message.TransportOperations.AddRange(storedMessage.TransportOperations); return true; }
public bool TryGet(string messageId, out OutboxMessage message) { StoredMessage storedMessage; message = null; var res = storage.TryGetValueAsync(_context.CurrentTransaction, messageId).Result; if (!res.HasValue) { return false; } storedMessage = res.Value; message = new OutboxMessage(messageId); message.TransportOperations.AddRange(ConvertStringToObject(storedMessage.TransportOperations)); return true; }
public bool TryGet(string messageId, out OutboxMessage message) { if (SkipGetOnce) { message = null; SkipGetOnce = false; Console.Out.WriteLine("Monkey: Message {0} was skipped, heheheh", messageId); return false; } var found = InnerPersister.TryGet(messageId, out message); Console.Out.WriteLine("Monkey: Message {0} was {1} in outbox", messageId, found ? "found" : "not found"); return found; }
public async Task Should_delete_all_OutboxRecords_that_have_been_dispatched() { var id = Guid.NewGuid().ToString("N"); var context = new ContextBag(); var persister = new OutboxPersister(store, "TestEndpoint"); using (var transaction = await persister.BeginTransaction(context)) { await persister.Store(new OutboxMessage("NotDispatched", new TransportOperation[0]), transaction, context); await transaction.Commit(); } var outboxMessage = 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(context)) { await persister.Store(outboxMessage, transaction, context); await transaction.Commit(); } await persister.SetAsDispatched(id, context); await Task.Delay(TimeSpan.FromSeconds(1)); //Need to wait for dispatch logic to finish //WaitForUserToContinueTheTest(store); WaitForIndexing(store); var cleaner = new OutboxRecordsCleaner(store); await cleaner.RemoveEntriesOlderThan(DateTime.UtcNow.AddMinutes(1)); using (var s = store.OpenAsyncSession()) { var result = await s.Query<OutboxRecord>().ToListAsync(); Assert.AreEqual(1, result.Count); Assert.AreEqual("NotDispatched", result[0].MessageId); } }
public async Task<OutboxMessage> Get(string messageId, ContextBag context) { using (new TransactionScope(TransactionScopeOption.Suppress, TransactionScopeAsyncFlowOption.Enabled)) using (var connection = connectionBuilder()) { await connection.OpenAsync(); using (var transaction = connection.BeginTransaction(IsolationLevel.ReadCommitted)) { OutboxMessage result; using (var command = connection.CreateCommand()) { command.CommandText = outboxCommands.Get; command.Transaction = transaction; command.AddParameter("MessageId", messageId); using (var dataReader = await command.ExecuteReaderAsync(CommandBehavior.SingleRow)) { if (!await dataReader.ReadAsync()) { return null; } var dispatched = dataReader.GetBoolean(0); if (dispatched) { result = new OutboxMessage(messageId, new TransportOperation[0]); } else { using (var textReader = dataReader.GetTextReader(1)) { var transportOperations = Serializer.Deserialize<IEnumerable<SerializableOperation>>(textReader) .FromSerializable() .ToArray(); result = new OutboxMessage(messageId, transportOperations); } } } } transaction.Commit(); return result; } } }
public bool TryGet(string messageId, out OutboxMessage message) { object[] possibleIds = { EndpointQualifiedMessageId(messageId), messageId, }; using (new TransactionScope(TransactionScopeOption.Suppress)) { OutboxRecord result; message = null; using (var session = SessionFactoryProvider.SessionFactory.OpenStatelessSession()) { using (var tx = session.BeginTransaction(IsolationLevel.ReadCommitted)) { //Explicitly using ICriteria instead of QueryOver for performance reasons. //It seems QueryOver uses quite a bit reflection and that takes longer. result = session.CreateCriteria <OutboxRecord>() .Add(Restrictions.In("MessageId", possibleIds)) .UniqueResult <OutboxRecord>(); tx.Commit(); } } if (result == null) { return(false); } message = new OutboxMessage(result.MessageId); if (!result.Dispatched) { var operations = ConvertStringToObject(result.TransportOperations); message.TransportOperations.AddRange(operations.Select(t => new TransportOperation(t.MessageId, t.Options, t.Message, t.Headers))); } return(true); } }
public bool TryGet(string messageId, out OutboxMessage message) { using (var conn = _connectionFactory()) { message = conn.Query<string>("SELECT transportoperations FROM outboxes WHERE messageId = :messageId", new {messageId}) .Select( r => { var m = new OutboxMessage(messageId); if (r != null) { m.TransportOperations.AddRange( _serializer.Deserialize<List<TransportOperation>>(r)); } return m; }).FirstOrDefault(); return message != default(OutboxMessage); } }
public async Task Should_save_with_not_dispatched() { var persister = new OutboxPersister(store, testEndpointName); 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 Task Store(OutboxMessage message, OutboxTransaction outboxTransaction, ContextBag context) { var sqlOutboxTransaction = (SqlOutboxTransaction) outboxTransaction; var transaction = sqlOutboxTransaction.Transaction; var connection = sqlOutboxTransaction.Connection; return Store(message, transaction, connection); }
internal async Task Store(OutboxMessage message, DbTransaction transaction, DbConnection connection) { using (var command = connection.CreateCommand()) { command.CommandText = outboxCommands.Store; command.Transaction = transaction; command.AddParameter("MessageId", message.MessageId); command.AddParameter("PersistenceVersion", StaticVersions.PersistenceVersion); command.AddParameter("Operations", Serializer.Serialize(message.TransportOperations.ToSerializable())); await command.ExecuteNonQueryEx(); } }
public async Task Should_update_dispatched_flag() { var persister = new OutboxPersister(store, testEndpointName); 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(); } await persister.SetAsDispatched(id, new ContextBag()); WaitForIndexing(store); using (var s = store.OpenAsyncSession()) { var result = await s.Query<OutboxRecord>() .SingleOrDefaultAsync(o => o.MessageId == id); Assert.NotNull(result); Assert.True(result.Dispatched); } }
public Task Store(OutboxMessage message, OutboxTransaction transaction, ContextBag options) { return TaskEx.CompletedTask; }