Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void Main()
- {
- using (var connection = new ConnectionFactory().CreateConnection())
- {
- using (var channel1 = connection.CreateModel())
- {
- // queue1 -> produce click to queue2
- // click -> exchange
- // queue2 -> consume click from queue1
- channel1.ExchangeDeclare("exchange", ExchangeType.Direct, autoDelete: true);
- channel1.QueueDeclare("queue1");
- channel1.QueueBind("queue1", "exchange", "queue1");
- channel1.QueueDeclare("queue2");
- channel1.QueueBind("queue2", "exchange", "queue2");
- var consumer1 = new EventingBasicConsumer(channel1);
- consumer1.Received += (sender, args) =>
- {
- try
- {
- using (var channel2 = connection.CreateModel())
- {
- Console.WriteLine("Click requested");
- channel2.BasicPublish("exchange", "queue2");
- }
- }
- catch (TimeoutException e)
- {
- Console.WriteLine(e);
- throw;
- }
- };
- channel1.BasicConsume(
- "queue1",
- autoAck: true,
- consumer1);
- var consumer2 = new EventingBasicConsumer(channel1);
- consumer2.Received += (sender, args) =>
- {
- Console.WriteLine("Click processed");
- };
- channel1.BasicConsume(
- "queue2",
- autoAck: true,
- consumer2);
- channel1.BasicPublish(
- "exchange",
- "queue1");
- Console.WriteLine("Publish to queue1. No timeout");
- Console.ReadLine();
- }
- }
- // ReSharper disable once FunctionNeverReturns
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement