Exemplo n.º 1
0
        public async Task <Guid> SendEnvelope(Envelope envelope)
        {
            if (envelope.Message == null)
            {
                throw new ArgumentNullException(nameof(envelope.Message));
            }

            var outgoing = _root.Router.Route(envelope);

            foreach (var env in outgoing)
            {
                _root.ApplyMessageTypeSpecificRules(env);
            }

            trackEnvelopeCorrelation(outgoing);

            if (!outgoing.Any())
            {
                _root.Logger.NoRoutesFor(envelope);

                throw new NoRoutesException(envelope);
            }

            await persistOrSend(outgoing);

            return(envelope.Id);
        }
Exemplo n.º 2
0
        public async Task <Guid> SendEnvelope(Envelope envelope)
        {
            if (envelope.Message == null && envelope.Data == null)
            {
                throw new ArgumentNullException(nameof(envelope.Message));
            }

            var outgoing = _root.Router.Route(envelope);

            if (envelope.IsDelayed(DateTime.UtcNow))
            {
                for (int i = 0; i < outgoing.Length; i++)
                {
                    _root.ApplyMessageTypeSpecificRules(outgoing[i]);

                    if (!outgoing[i].Subscriber.SupportsNativeScheduledSend)
                    {
                        outgoing[i] = outgoing[i].ForScheduledSend(new ScheduleSendSubscriber(this));
                    }
                }
            }
            else
            {
                foreach (var env in outgoing)
                {
                    _root.ApplyMessageTypeSpecificRules(env);
                }
            }



            trackEnvelopeCorrelation(outgoing);

            if (!outgoing.Any())
            {
                _root.Logger.NoRoutesFor(envelope);

                throw new NoRoutesException(envelope);
            }

            await persistOrSend(outgoing);

            return(envelope.Id);
        }