public Task <ICompletableSynchronizedStorageSession> TryAdapt(IOutboxTransaction transaction, ContextBag context, CancellationToken cancellationToken = default) { if (transaction is MongoOutboxTransaction mongoOutboxTransaction) { return(Task.FromResult((ICompletableSynchronizedStorageSession)mongoOutboxTransaction.StorageSession)); } return(emptyResult); }
public Task <ICompletableSynchronizedStorageSession> TryAdapt(IOutboxTransaction transaction, ContextBag context, CancellationToken cancellationToken = default) { if (transaction is NonDurableOutboxTransaction inMemOutboxTransaction) { ICompletableSynchronizedStorageSession session = new NonDurableSynchronizedStorageSession(inMemOutboxTransaction.Transaction); return(Task.FromResult(session)); } return(EmptyTask); }
public Task Store(OutboxMessage message, IOutboxTransaction transaction, ContextBag context, CancellationToken cancellationToken = default) { var mongoOutboxTransaction = (MongoOutboxTransaction)transaction; var storageSession = mongoOutboxTransaction.StorageSession; var storageTransportOperations = message.TransportOperations.Select(op => new StorageTransportOperation(op)).ToArray(); return(storageSession.InsertOneAsync(new OutboxRecord { Id = message.MessageId, TransportOperations = storageTransportOperations }, cancellationToken)); }
public Task <ICompletableSynchronizedStorageSession> TryAdapt(IOutboxTransaction transaction, ContextBag context, CancellationToken cancellationToken = default) { if (transaction is ServiceFabricOutboxTransaction outboxTransaction) { // this session will not own the transaction, the outbox part owns the transaction ICompletableSynchronizedStorageSession session = new StorageSession(outboxTransaction.StateManager, outboxTransaction.Transaction, outboxTransaction.TransactionTimeout, false); return(Task.FromResult(session)); } return(EmptyTask); }
public Task <ICompletableSynchronizedStorageSession> TryAdapt(IOutboxTransaction transaction, ContextBag context, CancellationToken cancellationToken = default) { if (transaction is CosmosOutboxTransaction cosmosOutboxTransaction) { cosmosOutboxTransaction.StorageSession.CurrentContextBag = context; currentSharedTransactionalBatchHolder?.SetCurrent(cosmosOutboxTransaction.StorageSession); return(Task.FromResult((ICompletableSynchronizedStorageSession)cosmosOutboxTransaction.StorageSession)); } return(emptyResult); }
public Task Store(OutboxMessage message, IOutboxTransaction transaction, ContextBag context, CancellationToken cancellationToken = default) { var tx = (NonDurableOutboxTransaction)transaction; tx.Enlist(() => { if (!storage.TryAdd(message.MessageId, new StoredMessage(message.MessageId, message.TransportOperations))) { throw new Exception($"Outbox message with id '{message.MessageId}' is already present in storage."); } }); return(Task.CompletedTask); }
public async Task Store(OutboxMessage message, IOutboxTransaction transaction, ContextBag context, CancellationToken cancellationToken = default) { var operations = new StoredTransportOperation[message.TransportOperations.Length]; for (var i = 0; i < message.TransportOperations.Length; i++) { var t = message.TransportOperations[i]; operations[i] = new StoredTransportOperation(t.MessageId, t.Options, t.Body.ToArray(), t.Headers); } var tx = ((ServiceFabricOutboxTransaction)transaction).Transaction; if (!await Outbox.TryAddAsync(tx, message.MessageId, new StoredOutboxMessage(message.MessageId, operations), transactionTimeout, cancellationToken).ConfigureAwait(false)) { throw new Exception($"Outbox message with id '{message.MessageId}' is already present in storage."); } }
public Task Store(OutboxMessage message, IOutboxTransaction transaction, ContextBag context, CancellationToken cancellationToken = default) { var cosmosTransaction = (CosmosOutboxTransaction)transaction; if (cosmosTransaction == null || cosmosTransaction.SuppressStoreAndCommit || cosmosTransaction.PartitionKey == null) { return(Task.CompletedTask); } cosmosTransaction.StorageSession.AddOperation(new OutboxStore(new OutboxRecord { Id = message.MessageId, TransportOperations = message.TransportOperations.Select(op => new StorageTransportOperation(op)).ToArray() }, cosmosTransaction.PartitionKey.Value, serializer, context)); return(Task.CompletedTask); }
public Task StoreAsync(OutboxMessage outboxMessage, IOutboxTransaction outboxTransaction) { var msSqlOutboxTransaction = (OutboxTransaction)outboxTransaction; var transaction = msSqlOutboxTransaction.Transaction; using (var command = _connection.CreateCommand()) { command.CommandText = StoreCommandText; command.CommandType = CommandType.Text; command.Transaction = transaction; command.AddParameter("MessageId", outboxMessage.MessageId); command.AddParameter("EndpointName", outboxMessage.EndpointName); command.AddParameter("CreatedAt", DateTime.UtcNow); command.AddParameter("Operations", JsonConvert.SerializeObject(outboxMessage.Operations, new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.Auto })); return(command.ExecuteNonQueryAsync()); } }
public void Begin() { _transaction = _outbox.BeginTransactionAsync().GetAwaiter().GetResult(); }
public ValueTask <bool> TryOpen(IOutboxTransaction transaction, ContextBag context, CancellationToken cancellationToken = new CancellationToken()) { throw new NotImplementedException("Outbox transactions are not supported in the testing framework."); }