Esempio n. 1
0
        public async Task Send(ConsumeContext <TMessage> context, IPipe <ConsumeContext <TMessage> > next)
        {
            if (context.RequestId.HasValue)
            {
                var clientId = context.Headers.Get(MessageHeaders.ClientId, default(Guid?));
                if (clientId.HasValue)
                {
                    var acceptedContext = await _endpoint.Accept(clientId.Value, context.RequestId.Value).ConfigureAwait(false);

                    context.AddOrUpdatePayload(() => acceptedContext, existing => acceptedContext);

                    await next.Send(context).ConfigureAwait(false);
                }
                else
                {
                    var exception = new RequestException($"ClientId not specified (requestId: {context.RequestId})");

                    await context.NotifyFaulted(TimeSpan.Zero, TypeMetadataCache <ConductorMessageFilter <TMessage> > .ShortName, exception).ConfigureAwait(false);
                }
            }
            else
            {
                var exception = new RequestException("RequestId is required");

                await context.NotifyFaulted(TimeSpan.Zero, TypeMetadataCache <ConductorMessageFilter <TMessage> > .ShortName, exception).ConfigureAwait(false);
            }
        }
        public async Task Send(ConsumerConsumeContext <TConsumer, TMessage> context, IPipe <ConsumerConsumeContext <TConsumer, TMessage> > next)
        {
            if (!context.RequestId.HasValue)
            {
                throw new RequestException("RequestId is required");
            }

            var clientId = context.Headers.Get(MessageHeaders.ClientId, default(Guid?));

            if (!clientId.HasValue)
            {
                throw new RequestException($"ClientId not specified (requestId: {context.RequestId})");
            }

            var acceptedContext = await _endpoint.Accept(clientId.Value, context.RequestId.Value).ConfigureAwait(false);

            context.AddOrUpdatePayload(() => acceptedContext, existing => acceptedContext);

            await next.Send(context).ConfigureAwait(false);
        }