Exemple #1
0
        async Task Dispatch(CapturedTransportOperation operation, RootContext rootContext)
        {
            using (var conn = settings.Links[operation.Destination].ConnectionFactory())
            {
                await conn.OpenAsync().ConfigureAwait(false);

                using (var trans = conn.BeginTransaction())
                {
                    //Will block until the record insert transaction is completed.
                    await OutboxPersister.MarkAsDispatched(operation, conn, trans).ConfigureAwait(false);

                    var iface = settings.GetDestinationInterface(operation.Destination);

                    var chains          = rootContext.Interfaces.GetChainsFor(iface);
                    var chain           = chains.Get <AnycastContext>();
                    var dispatchContext = new OutboxDispatchContext(rootContext, iface);
                    var forwardContext  = new AnycastContext(operation.Destination, operation.OutgoingMessage, DistributionStrategyScope.Send, dispatchContext);
                    dispatchContext.Set(new TransportTransaction());
                    await chain.Invoke(forwardContext).ConfigureAwait(false);

                    //Only commit the transaction if the dispatch succeeded.
                    trans.Commit();
                }
            }
        }
 public OutboxPersisterRunner(OutboxPersister persister, Func <SqlConnection> connectionFactory)
 {
     this.persister         = persister;
     this.connectionFactory = connectionFactory;
 }