Ejemplo n.º 1
0
        public Task Send(ConsumerConsumeContext <TConsumer> context)
        {
            if (context is ConsumerConsumeContext <TConsumer, TMessage> consumerContext)
            {
                return(_output.Send(consumerContext));
            }

            if (context.TryGetMessage(out ConsumeContext <TMessage> messageContext))
            {
                return(_output.Send(new ConsumerConsumeContextProxy <TConsumer, TMessage>(messageContext, context.Consumer)));
            }

            throw new ArgumentException($"THe message could not be retrieved: {TypeMetadataCache<TMessage>.ShortName}", nameof(context));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// The middleware filter
        /// </summary>
        /// <param name="context"></param>
        /// <param name="next"></param>
        /// <returns></returns>
        public async Task Send(ConsumerConsumeContext <TConsumer> context, IPipe <ConsumerConsumeContext <TConsumer> > next)
        {
            try
            {
                ConsumeContext <JToken> jsonContext;
                if (context.TryGetMessage(out jsonContext))
                {
                    var message        = jsonContext.Message;
                    var messageRequest = message.ToObject <EmailMessage>();

                    if (!RegexUtilities.IsValidEmail(messageRequest.To))
                    {
                        throw new Exception("Exception occour :Email address is invalid");
                    }
                }
                await next.Send(context);
            }
            catch (Exception ex)
            {
                await Console.Out.WriteLineAsync($"An exception occurred: {ex.Message}");

                throw;
            }
        }