public static RabbitMqProducer Create(string queue, string exchange = "", bool autoDelete = false)
        {
            var producer = new RabbitMqProducer();

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

            if (!string.IsNullOrWhiteSpace(queue))
            {
                producer.BindQueue(queue, autoDelete);
            }


            return(producer);
        }
Beispiel #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);
        }