Exemplo n.º 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 async Task Start(RootContext rootContext, SettingsHolder extensibilitySettings)
        {
            tokenSource = new CancellationTokenSource();

            foreach (var persister in persisters)
            {
                async Task Dispatch(OutgoingMessage operation)
                {
                    var destinationEndpoint = persister.Key;
                    var iface = destinationToInterfaceMap[destinationEndpoint];

                    var chains          = rootContext.Interfaces.GetChainsFor(iface);
                    var chain           = chains.Get <AnycastContext>();
                    var dispatchContext = new OutboxDispatchContext(rootContext, iface);
                    var forwardContext  = new AnycastContext(destinationEndpoint, operation, DistributionStrategyScope.Send, dispatchContext);

                    dispatchContext.Set(new TransportTransaction());
                    await chain.Invoke(forwardContext).ConfigureAwait(false);
                }

                await persister.Value.Start(tokenSource.Token, Dispatch);
            }
        }