public Task RouteBatches(IEnumerable <BatchInternal> outgoingBatches, ReceiveContextInternal context, DispatchConsistency consistency)
        {
            var pendingBatches = new List <Task>();

            foreach (var batch in outgoingBatches)
            {
                pendingBatches.Add(RouteBatch(batch, context as BrokeredMessageReceiveContextInternal, consistency));
            }
            return(Task.WhenAll(pendingBatches));
        }
        static bool TryGetReceiveContext(TransportTransaction transportTransaction, out ReceiveContextInternal receiveContext)
        {
            if (transportTransaction == null)
            {
                receiveContext = null;
                return(false);
            }

            return(transportTransaction.TryGet(out receiveContext));
        }
        RoutingOptionsInternal GetRoutingOptions(ReceiveContextInternal receiveContext, DispatchConsistency consistency)
        {
            var sendVia = false;
            var context = receiveContext as BrokeredMessageReceiveContextInternal;

            if (context?.Recovering == false) // avoid send via when recovering to prevent error message from rolling back
            {
                sendVia  = sendViaFromConfiguration & transportTypeIsNetMessaging;
                sendVia &= consistency != DispatchConsistency.Isolated;
            }
            return(new RoutingOptionsInternal
            {
                SendVia = sendVia,
                ViaEntityPath = GetViaEntityPathFor(context?.Entity),
                ViaConnectionString = context?.Entity.Namespace.ConnectionString,
                ViaPartitionKey = context?.IncomingBrokeredMessage.PartitionKey
            });
        }