static void Main(string[] args) { using (IConnectionFactory connectionFactory = new CachingConnectionFactory()) { IAmqpAdmin amqpAdmin = new RabbitAdmin(connectionFactory); //Each queue is automatically bound to the default direct exchange. amqpAdmin.DeclareQueue(new Queue(ConfigurationManager.AppSettings["STOCK_REQUEST_QUEUE_NAME"])); amqpAdmin.DeclareQueue(new Queue(ConfigurationManager.AppSettings["STOCK_RESPONSE_QUEUE_NAME"])); TopicExchange mktDataExchange = new TopicExchange(ConfigurationManager.AppSettings["MARKET_DATA_EXCHANGE_NAME"], false, false); amqpAdmin.DeclareExchange(mktDataExchange); Queue mktDataQueue = new Queue(ConfigurationManager.AppSettings["MARKET_DATA_QUEUE_NAME"]); amqpAdmin.DeclareQueue(mktDataQueue); Console.WriteLine("Queues and exchanges have been declared."); Console.WriteLine("Press 'enter' to exit"); Console.ReadLine(); } }
public Binding(Queue queue, TopicExchange exchange) { this.queue = queue.Name; this.exchange = exchange.Name; this.routingKey = ""; }
public void TestSendAndReceiveWithTopicTwoCallbacks() { var admin = new RabbitAdmin(this.connectionFactory); var exchange = new TopicExchange("topic"); admin.DeclareExchange(exchange); this.template.Exchange = exchange.Name; admin.DeclareBinding(BindingBuilder.Bind(queue).To(exchange).With("*.end")); this.template.Execute<object>(delegate(IModel channel) { var consumer = this.CreateConsumer(this.template); var tag = consumer.ConsumerTag; Assert.IsNotNull(tag); try { this.template.ConvertAndSend("foo", "message"); var result = this.GetResult(consumer); Assert.AreEqual(null, result); } finally { try { channel.BasicCancel(tag); } catch (Exception e) { // TODO: this doesn't make sense. Looks like there is a bug in the rabbitmq.client code here: http://hg.rabbitmq.com/rabbitmq-dotnet-client/file/2f12b3b4d6bd/projects/client/RabbitMQ.Client/src/client/impl/ModelBase.cs#l1018 Console.WriteLine(e.Message); } } return null; }); this.template.Execute<object>(delegate(IModel channel) { var consumer = this.CreateConsumer(this.template); var tag = consumer.ConsumerTag; Assert.IsNotNull(tag); try { // TODO: Bug here somewhere... this.template.ConvertAndSend("foo.end", "message"); var result = this.GetResult(consumer); Assert.AreEqual("message", result); } finally { try { channel.BasicCancel(tag); } catch (Exception e) { // TODO: this doesn't make sense. Looks like there is a bug in the rabbitmq.client code here: http://hg.rabbitmq.com/rabbitmq-dotnet-client/file/2f12b3b4d6bd/projects/client/RabbitMQ.Client/src/client/impl/ModelBase.cs#l1018 Console.WriteLine(e.Message); } } return null; }); }
private void StockForm_Load(object sender, EventArgs e) { try { using (IConnectionFactory connectionFactory = new CachingConnectionFactory()) { IAmqpAdmin amqpAdmin = new RabbitAdmin(connectionFactory); TopicExchange mktDataExchange = new TopicExchange("APP.STOCK.MARKETDATA", false, false); amqpAdmin.DeclareExchange(mktDataExchange); Spring.Messaging.Amqp.Core.Queue mktDataQueue = new Spring.Messaging.Amqp.Core.Queue("APP.STOCK.MARKETDATA"); amqpAdmin.DeclareQueue(mktDataQueue); //Create the Exchange for MarketData Requests if it does not already exist. //amqpAdmin.DeclareBinding(BindingBuilder.Bind(mktDataQueue).To(mktDataExchange).With(_currentBinding)); //Set up initial binding RebindQueue("APP.STOCK.QUOTES.nasdaq.*"); } } catch (Exception ex) { log.ErrorFormat("Uncaught application exception.", ex); } }
public Binding(Queue queue, TopicExchange exchange, String routingKey) { this.queue = queue.Name; this.exchange = exchange.Name; this.routingKey = routingKey; }
private void RebindQueue(string routingKey) { var ctx = ContextRegistry.GetContext(); var factory = ctx.GetObject("ConnectionFactory") as IConnectionFactory; try { IAmqpAdmin amqpAdmin = new RabbitAdmin(factory); TopicExchange mktDataExchange = new TopicExchange("APP.STOCK.MARKETDATA", false, false); Spring.Messaging.Amqp.Core.Queue mktDataQueue = new Spring.Messaging.Amqp.Core.Queue("APP.STOCK.MARKETDATA"); if (!string.IsNullOrEmpty(_currentBinding)) amqpAdmin.RemoveBinding(BindingBuilder.Bind(mktDataQueue).To(mktDataExchange).With(_currentBinding)); _currentBinding = routingKey; if (!string.IsNullOrEmpty(_currentBinding)) { amqpAdmin.DeclareBinding(BindingBuilder.Bind(mktDataQueue).To(mktDataExchange).With(_currentBinding)); txtRoutingKey.Text = _currentBinding; } } catch (Exception ex) { log.ErrorFormat("Uncaught application exception.", ex); } }
/// <summary>The to.</summary> /// <param name="exchange">The exchange.</param> /// <returns>The topic exchange routing key configurer.</returns> public TopicExchangeRoutingKeyConfigurer To(TopicExchange exchange) { return(new TopicExchangeRoutingKeyConfigurer(this, exchange)); }
public void TestSendAndReceiveWithTopicTwoCallbacks() { var admin = new RabbitAdmin(this.connectionFactory); var exchange = new TopicExchange("topic"); admin.DeclareExchange(exchange); this.template.Exchange = exchange.Name; admin.DeclareBinding(BindingBuilder.Bind(queue).To(exchange).With("*.end")); this.template.Execute<object>( delegate { var consumer = this.CreateConsumer(this.template); var tag = consumer.ConsumerTag; Assert.IsNotNull(tag); try { this.template.ConvertAndSend("foo", "message"); var result = this.GetResult(consumer); Assert.AreEqual(null, result); } finally { consumer.Stop(); } return null; }); this.template.Execute<object>( delegate { var consumer = this.CreateConsumer(this.template); var tag = consumer.ConsumerTag; Assert.IsNotNull(tag); try { this.template.ConvertAndSend("foo.end", "message"); var result = this.GetResult(consumer); Assert.AreEqual("message", result); } finally { consumer.Stop(); } return null; }); }
public void TestSendAndReceiveWithTopicConsumeInBackground() { var admin = new RabbitAdmin(this.connectionFactory); var exchange = new TopicExchange("topic"); admin.DeclareExchange(exchange); this.template.Exchange = exchange.Name; admin.DeclareBinding(BindingBuilder.Bind(queue).To(exchange).With("*.end")); var template = new RabbitTemplate(new CachingConnectionFactory()); template.Exchange = exchange.Name; var consumer = this.template.Execute( delegate { var consumerinside = this.CreateConsumer(template); var tag = consumerinside.ConsumerTag; Assert.IsNotNull(tag); return consumerinside; }); template.ConvertAndSend("foo", "message"); var result = this.GetResult(consumer); Assert.AreEqual(null, result); this.template.ConvertAndSend("foo.end", "message"); result = this.GetResult(consumer); Assert.AreEqual("message", result); consumer.Stop(); }
private void StockForm_Load(object sender, EventArgs e) { accountNameTextBox.Text = DefaultAccountName; tradeQuantityNumericUpDown.Value = DefaultTradeRequestQuantity; txtRoutingKey.Text = DefaultRoutingKey; tradeOperationsGroupBox.Enabled = false; try { using (IConnectionFactory connectionFactory = new CachingConnectionFactory()) { IAmqpAdmin amqpAdmin = new RabbitAdmin(connectionFactory); TopicExchange mktDataExchange = new TopicExchange("app.stock.marketdata", false, false); amqpAdmin.DeclareExchange(mktDataExchange); Spring.Messaging.Amqp.Core.Queue mktDataQueue = new Spring.Messaging.Amqp.Core.Queue("app.stock.marketdata"); amqpAdmin.DeclareQueue(mktDataQueue); //Create the Exchange for MarketData Requests if it does not already exist. //amqpAdmin.DeclareBinding(BindingBuilder.Bind(mktDataQueue).To(mktDataExchange).With(_currentBinding)); //Set up initial binding RebindQueue(DefaultRoutingKey); } } catch (Exception ex) { log.ErrorFormat("Uncaught application exception.", ex); } }