Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using RabbitMQ.Client;
- using RabbitMQ.Client.Framing;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace nadawca
- {
- class Program
- {
- static void Main(string[] args)
- {
- var factory = new ConnectionFactory()
- {
- UserName = "iadcjwaz",
- Password = "VO6QP1IZkX8JnG4y4YlrDL5TJw3CjYAn",
- HostName = "lark.rmq.cloudamqp.com",
- VirtualHost = "iadcjwaz"
- };
- using (var connection = factory.CreateConnection())
- using (var channel = connection.CreateModel())
- {
- string replyQueueName = channel.QueueDeclare().QueueName;
- QueueingBasicConsumer consumer = new QueueingBasicConsumer(channel);
- channel.BasicConsume(replyQueueName, true, consumer);
- IBasicProperties properties = channel.CreateBasicProperties();
- //Topic
- //var messageBytes = Encoding.UTF8.GetBytes("5");
- //properties.Headers = new Dictionary<string, object>();
- //channel.BasicPublish("top_rout", "quick.orange.fox", properties, messageBytes);
- //Console.WriteLine("Wyslano na kolejke powiększenie liczby 5 o 1");
- //messageBytes = Encoding.UTF8.GetBytes("15");
- //properties.Headers = new Dictionary<string, object>();
- //channel.BasicPublish("top_rout", "lazy.brown.fox", properties, messageBytes);
- //Console.WriteLine("Wyslano na kolejke powiększenie liczby 15 o 1");
- //messageBytes = Encoding.UTF8.GetBytes("25");
- //properties.Headers = new Dictionary<string, object>();
- //channel.BasicPublish("top_rout", "quick.orange.rabbit", properties, messageBytes);
- //Console.WriteLine("Wyslano na kolejke powiększenie liczby 25 o 1");
- //messageBytes = Encoding.UTF8.GetBytes("35");
- //properties.Headers = new Dictionary<string, object>();
- //channel.BasicPublish("top_rout", "quick.brown.fox", properties, messageBytes);
- //Console.WriteLine("Wyslano na kolejke powiększenie liczby 35 o 1");
- //Header
- BasicProperties props = new BasicProperties();
- channel.ExchangeDeclare("head_rout", "headers");
- var messageBytes = Encoding.UTF8.GetBytes("9");
- Console.WriteLine("Wyslano na kolejke zadanie dodawania liczby 1 i 9");
- props.Headers = new Dictionary<string, object>{
- { "x-match", "any" }, //any or all
- { "liczba", 9 }
- };
- channel.BasicPublish("head_rout", "", props, messageBytes);
- messageBytes = Encoding.UTF8.GetBytes("100");
- Console.WriteLine("Wyslano na kolejke zadanie dodawania liczby 1 i 100");
- props.Headers = new Dictionary<string, object>();
- props.Headers.Add("x-match", "any");
- props.Headers.Add("liczba", 100);
- channel.BasicPublish("head_rout", "", props, messageBytes);
- messageBytes = Encoding.UTF8.GetBytes("256");
- Console.WriteLine("Wyslano na kolejke zadanie dodawania liczby 1 i 256");
- props.Headers = new Dictionary<string, object>();
- props.Headers.Add("x-match", "any");
- props.Headers.Add("liczba", 256);
- channel.BasicPublish("head_rout", "", props, messageBytes);
- messageBytes = Encoding.UTF8.GetBytes("900");
- Console.WriteLine("Wyslano na kolejke zadanie dodawania liczby 1 i 900");
- props.Headers = new Dictionary<string, object>();
- props.Headers.Add("x-match", "any");
- props.Headers.Add("liczba", 900);
- channel.BasicPublish("head_rout", "", props, messageBytes);
- }
- Console.ReadKey();
- }
- }
- }
Add Comment
Please, Sign In to add comment