/// <summary>
        /// Ctor with a key to lookup the configuration
        /// </summary>
        /// <param name="settings"></param>
        /// <param name="instanceName"></param>
        /// <param name="exchangeName"></param>
        /// <param name="processingQueueName"></param>
        /// <param name="subscriptions"></param>
        public RabbitReceiver(RabbitConnectionSettings settings, string instanceName,
                              string exchangeName, string processingQueueName,
                              List <string> subscriptions, IQuoteService quoteService)
        {
            base._connectionSettings = settings;
            InstanceName             = instanceName;
            ProcessingQueue          = processingQueueName;
            Exchange      = exchangeName;
            Subscriptions = subscriptions;
            QuoteService  = quoteService;
            base.ConfigureConnection();

            Enabled = true;

            //Setup Pattern
            _model.BasicQos(0, 1, false);
            _model.ExchangeDeclare(exchangeName, ExchangeType.Topic, true);
            _model.QueueDeclare(processingQueueName, false, false, false, null);

            if (subscriptions == null)
            {
                return;
            }
            foreach (var subscription in subscriptions)
            {
                _model.QueueBind(processingQueueName, exchangeName, subscription.ToLower());
            }
        }
Example #2
0
        private void sendButton_Click(object sender, EventArgs e)
        {
            responsesTextBox.Text = string.Empty;
            Application.DoEvents();

            var rabbitConnectionSettings = new Shared.RabbitConnectionSettings
            {
                HostName = "localhost",
                Password = "******",
                Username = "******"
            };

            const string quoteExchangeName = "HealthInsuranceQuoteExchange";

            var routingKeys = new List <string> {
                "ProductId", _request.Product.ToString()
            };

            AddText("Requesting quote for product: " + _request.Product.ToString());
            using (var client = new RabbitSender <Shared.Contracts.QuoteRequest, Shared.Contracts.QuoteResponse>(rabbitConnectionSettings, quoteExchangeName))
            {
                var responses = client.Send(_request, routingKeys, new TimeSpan(0, 0, _request.TimeoutSeconds), _request.MinimumResponses);
                AddText(string.Format("There are: {0} responses", responses.Count()));
                foreach (var response in responses)
                {
                    AddText(string.Format("Company: {0} - Price: {1}", response.Company, response.Price));
                }
            }
        }
        /// <summary>
        /// Ctor
        /// </summary>
        /// <param name="exchangeName">The name of the exchange to use for sending messages</param>
        /// <param name="settings">The connection settings for the rabbit server</param>
        public RabbitSender(RabbitConnectionSettings settings, string exchangeName)
        {
            _exchangeName            = exchangeName;
            base._connectionSettings = settings;
            base.ConfigureConnection();

            //Configure for pattern
            _model.ExchangeDeclare(_exchangeName, ExchangeType.Topic, true); //Setup exchange and configure it for topic pattern
            _responseQueue = _model.QueueDeclare().QueueName;                //Declare a random queue for the response
            _consumer      = new QueueingBasicConsumer(_model);
            _model.BasicConsume(_responseQueue, true, _consumer);
        }