Advertisement
Guest User

Untitled

a guest
May 8th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.30 KB | None | 0 0
  1. using RabbitMQ.Client;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace nadawca
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             var factory = new ConnectionFactory()
  15.             {
  16.                 UserName = "iadcjwaz",
  17.                 Password = "VO6QP1IZkX8JnG4y4YlrDL5TJw3CjYAn",
  18.                 HostName = "lark.rmq.cloudamqp.com",
  19.                 VirtualHost = "iadcjwaz"
  20.             };
  21.             using (var connection = factory.CreateConnection())
  22.             using (var channel = connection.CreateModel())
  23.             {
  24.                 string replyQueueName = channel.QueueDeclare().QueueName;
  25.                 QueueingBasicConsumer consumer = new QueueingBasicConsumer(channel);
  26.                 channel.BasicConsume(replyQueueName, true, consumer);
  27.  
  28.                 IBasicProperties properties = channel.CreateBasicProperties();
  29.  
  30.                 //Topic
  31.  
  32.                 var messageBytes = Encoding.UTF8.GetBytes("5");
  33.                 properties.Headers = new Dictionary<string, object>();
  34.                 channel.BasicPublish("top_rout", "quick.orange.fox", properties, messageBytes);
  35.                 Console.WriteLine("Wyslano na kolejke powiększenie liczby 5 o 1");
  36.  
  37.                 messageBytes = Encoding.UTF8.GetBytes("15");
  38.                 properties.Headers = new Dictionary<string, object>();
  39.                 channel.BasicPublish("top_rout", "lazy.brown.fox", properties, messageBytes);
  40.                 Console.WriteLine("Wyslano na kolejke powiększenie liczby 15 o 1");
  41.  
  42.                 messageBytes = Encoding.UTF8.GetBytes("25");
  43.                 properties.Headers = new Dictionary<string, object>();
  44.                 channel.BasicPublish("top_rout", "quick.orange.rabbit", properties, messageBytes);
  45.                 Console.WriteLine("Wyslano na kolejke powiększenie liczby 25 o 1");
  46.  
  47.                 messageBytes = Encoding.UTF8.GetBytes("35");
  48.                 properties.Headers = new Dictionary<string, object>();
  49.                 channel.BasicPublish("top_rout", "quick.brown.fox", properties, messageBytes);
  50.                 Console.WriteLine("Wyslano na kolejke powiększenie liczby 35 o 1");
  51.             }
  52.             Console.ReadKey();
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement