示例#1
0
        public override Task ConsumeAsync(ConsumedMessage <Request> message)
        {
            return(Task.Factory
                   .StartNew(() =>
            {
                Console.WriteLine("[{0}]received '{1}' by '{2}' with correlation id {3}",
                                  message.ConsumerTag,
                                  message.Headers.MessageId,
                                  GetType().Name,
                                  message.Headers.CorrelationId);

                var exchange = _broker.DeclareDirectExchange(message.Headers
                                                             .ReplyConfiguration
                                                             .ExchangeName);
                var queue = _broker.DeclareQueue(message.Headers
                                                 .ReplyConfiguration
                                                 .RoutingKey);
                _broker.DeclareExchangeBinding(exchange,
                                               queue,
                                               message.Headers.ReplyConfiguration.RoutingKey);

                var outboundMessage = new OutboundMessage <Response>(new Response
                {
                    BarBar = message.Content.Bar * 2
                });
                outboundMessage.SetCorrelationId(message.Headers.CorrelationId);
                _connection.PublishAsync(outboundMessage,
                                         exchange,
                                         message.Headers.ReplyConfiguration.RoutingKey);
            }));
        }
示例#2
0
        private static Queue BindQueue(IBroker broker, String queueName, Exchange exchange)
        {
            var queue = broker.DeclareQueue(queueName);

            broker.TryDeclareExchangeBinding(exchange, queue, RoutingKey);
            return(queue);
        }
示例#3
0
 private static Queue BindQueue(IBroker broker, String queueName, Exchange exchange)
 {
     var queue = broker.DeclareQueue(queueName);
     broker.TryDeclareExchangeBinding(exchange, queue, RoutingKey);
     return queue;
 }