Guest User

Untitled

a guest
May 8th, 2017
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.11 KB | None | 0 0
  1. using RabbitMQ.Client;
  2. using RabbitMQ.Client.Framing;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8.  
  9. namespace nadawca
  10. {
  11. class Program
  12. {
  13. static void Main(string[] args)
  14. {
  15. var factory = new ConnectionFactory()
  16. {
  17. UserName = "iadcjwaz",
  18. Password = "VO6QP1IZkX8JnG4y4YlrDL5TJw3CjYAn",
  19. HostName = "lark.rmq.cloudamqp.com",
  20. VirtualHost = "iadcjwaz"
  21. };
  22. using (var connection = factory.CreateConnection())
  23. using (var channel = connection.CreateModel())
  24. {
  25. string replyQueueName = channel.QueueDeclare().QueueName;
  26. QueueingBasicConsumer consumer = new QueueingBasicConsumer(channel);
  27. channel.BasicConsume(replyQueueName, true, consumer);
  28.  
  29. IBasicProperties properties = channel.CreateBasicProperties();
  30.  
  31. //Topic
  32.  
  33. //var messageBytes = Encoding.UTF8.GetBytes("5");
  34. //properties.Headers = new Dictionary<string, object>();
  35. //channel.BasicPublish("top_rout", "quick.orange.fox", properties, messageBytes);
  36. //Console.WriteLine("Wyslano na kolejke powiększenie liczby 5 o 1");
  37.  
  38. //messageBytes = Encoding.UTF8.GetBytes("15");
  39. //properties.Headers = new Dictionary<string, object>();
  40. //channel.BasicPublish("top_rout", "lazy.brown.fox", properties, messageBytes);
  41. //Console.WriteLine("Wyslano na kolejke powiększenie liczby 15 o 1");
  42.  
  43. //messageBytes = Encoding.UTF8.GetBytes("25");
  44. //properties.Headers = new Dictionary<string, object>();
  45. //channel.BasicPublish("top_rout", "quick.orange.rabbit", properties, messageBytes);
  46. //Console.WriteLine("Wyslano na kolejke powiększenie liczby 25 o 1");
  47.  
  48. //messageBytes = Encoding.UTF8.GetBytes("35");
  49. //properties.Headers = new Dictionary<string, object>();
  50. //channel.BasicPublish("top_rout", "quick.brown.fox", properties, messageBytes);
  51. //Console.WriteLine("Wyslano na kolejke powiększenie liczby 35 o 1");
  52.  
  53.  
  54. //Header
  55. BasicProperties props = new BasicProperties();
  56. channel.ExchangeDeclare("head_rout", "headers");
  57.  
  58. var messageBytes = Encoding.UTF8.GetBytes("9");
  59. Console.WriteLine("Wyslano na kolejke zadanie dodawania liczby 1 i 9");
  60. props.Headers = new Dictionary<string, object>{
  61. { "x-match", "any" }, //any or all
  62. { "liczba", 9 }
  63. };
  64. channel.BasicPublish("head_rout", "", props, messageBytes);
  65.  
  66. messageBytes = Encoding.UTF8.GetBytes("100");
  67. Console.WriteLine("Wyslano na kolejke zadanie dodawania liczby 1 i 100");
  68. props.Headers = new Dictionary<string, object>();
  69. props.Headers.Add("x-match", "any");
  70. props.Headers.Add("liczba", 100);
  71. channel.BasicPublish("head_rout", "", props, messageBytes);
  72.  
  73. messageBytes = Encoding.UTF8.GetBytes("256");
  74. Console.WriteLine("Wyslano na kolejke zadanie dodawania liczby 1 i 256");
  75. props.Headers = new Dictionary<string, object>();
  76. props.Headers.Add("x-match", "any");
  77. props.Headers.Add("liczba", 256);
  78. channel.BasicPublish("head_rout", "", props, messageBytes);
  79.  
  80. messageBytes = Encoding.UTF8.GetBytes("900");
  81. Console.WriteLine("Wyslano na kolejke zadanie dodawania liczby 1 i 900");
  82. props.Headers = new Dictionary<string, object>();
  83. props.Headers.Add("x-match", "any");
  84. props.Headers.Add("liczba", 900);
  85. channel.BasicPublish("head_rout", "", props, messageBytes);
  86. }
  87. Console.ReadKey();
  88. }
  89. }
  90. }
Add Comment
Please, Sign In to add comment