Exemplo n.º 1
0
        public Task <TResponse> RequestAsync <TRequest, TResponse>(TRequest message = default(TRequest), Guid globalMessageId = new Guid(),
                                                                   Action <IRequestConfigurationBuilder> configuration = null)
        {
            var config = _configEval.GetConfiguration <TRequest, TResponse>(configuration);

            var exchangeCfg = config.Exchange.AssumeInitialized
                                ? null
                                : new ExchangeDeclaration
            {
                AutoDelete   = config.Exchange.AutoDelete,
                Durable      = config.Exchange.Durable,
                ExchangeType = config.Exchange.ExchangeType,
                Name         = config.Exchange.ExchangeName
            };
            var queueCfg = config.Queue.AssumeInitialized
                                ? null
                                : new QueueDeclaration
            {
                Arguments  = config.Queue.Arguments,
                Durable    = config.Queue.Durable,
                AutoDelete = config.Queue.AutoDelete,
                Exclusive  = config.Queue.Exclusive,
                Name       = config.Queue.FullQueueName
            };
            var requestConfig = new Operations.Request.Configuration.RequestConfiguration
            {
                Request = new PublisherConfiguration
                {
                    Exchange        = exchangeCfg,
                    ExchangeName    = config.Exchange.ExchangeName,
                    BasicProperties = new BasicProperties(),
                    RoutingKey      = config.RoutingKey,
                    Mandatory       = false
                },
                Response = new ConsumerConfiguration
                {
                    Exchange = exchangeCfg,
                    Queue    = queueCfg,
                    Consume  = new ConsumeConfiguration
                    {
                        ExchangeName = config.Exchange.ExchangeName,
                        ConsumerTag  = Guid.NewGuid().ToString(),
                        AutoAck      = config.AutoAck,
                        RoutingKey   = config.ReplyQueueRoutingKey,
                        QueueName    = config.Queue.FullQueueName
                    }
                }
            };
            Action <IPipeContext> ctxAction = context =>
            {
                context.Properties.TryAdd(RequestKey.Configuration, requestConfig);
                context.Properties.TryAdd(PipeKey.PublisherConfiguration, requestConfig.Request);
                context.Properties.TryAdd(PipeKey.ConsumerConfiguration, requestConfig.Response);
                context.Properties.TryAdd(PipeKey.ConsumeConfiguration, requestConfig.Response.Consume);
            };

            return(_client.RequestAsync <TRequest, TResponse>(message, ctxAction));
        }
Exemplo n.º 2
0
 public Task <TResponse> RequestAsync <TRequest, TResponse>(TRequest message = default(TRequest), Guid globalMessageId = new Guid(),
                                                            Action <IRequestConfigurationBuilder> configuration = null)
 {
     return(_client.RequestAsync <TRequest, TResponse>(message, globalMessageId, configuration));
 }