예제 #1
0
        public static RabbitMqReceiver Create(string queue, EventHandler <BasicDeliverEventArgs> callback, string exchange = "", bool autoDelete = false)
        {
            var receiver = new RabbitMqReceiver();

            receiver.Connect();
            if (!string.IsNullOrWhiteSpace(exchange))
            {
                receiver.BindExchange(exchange);
            }

            receiver.BindQueue(queue, autoDelete);
            receiver.DeclareReceived(callback);

            return(receiver);
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RabbitMqScatterGatter"/> class.
        /// Prepares all producers, receivers and the response list.
        /// </summary>
        /// <param name="outgoingQueues">The queues wanting to sent messages out to.</param>
        /// <param name="incomingQueue">The queue where responses will be coming back to.</param>
        public RabbitMqScatterGatter(IEnumerable <string> outgoingQueues, string incomingQueue)
        {
            _timer     = new Timer();
            _responses = new Dictionary <string, double>();
            _producers = new List <RabbitMqProducer>();


            foreach (var outgoingQueue in outgoingQueues)
            {
                var producer = new RabbitMqProducer();
                producer.Connect();
                producer.BindQueue(outgoingQueue);
                _producers.Add(producer);

                // Outgoing queue is the applicationId so this can be used for the key as well.
                _responses.Add(outgoingQueue, 0);
            }

            _receiver = new RabbitMqReceiver();
            _receiver.Connect();
            _receiver.BindQueue(incomingQueue);
            _receiver.DeclareReceived(ConsumerReceived);
        }