Advertisement
Guest User

Untitled

a guest
May 8th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.67 KB | None | 0 0
  1. using RabbitMQ.Client;
  2. using RabbitMQ.Client.Events;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8.  
  9. namespace rabbit2
  10. {
  11.     class Program
  12.     {
  13.         private static int plusJeden(int n)
  14.         {
  15.             return n + 1;
  16.         }
  17.         static void Main(string[] args)
  18.         {
  19.             var factory = new ConnectionFactory()
  20.             {
  21.                 UserName = "iadcjwaz",
  22.                 Password = "VO6QP1IZkX8JnG4y4YlrDL5TJw3CjYAn",
  23.                 HostName = "lark.rmq.cloudamqp.com",
  24.                 VirtualHost = "iadcjwaz"
  25.             };
  26.             using (var connection = factory.CreateConnection())
  27.             using (var channel = connection.CreateModel())
  28.             {
  29.                 channel.ExchangeDeclare("top_rout", "topic");
  30.                 var queueName = channel.QueueDeclare().QueueName;
  31.                 channel.QueueBind(queueName, "top_rout", "#.#.rabbit");
  32.                 var consumer = new EventingBasicConsumer(channel);
  33.  
  34.  
  35.                 Console.WriteLine("Odbiorca jest aktywny");
  36.  
  37.                 consumer.Received += (model, ea) =>
  38.                 {
  39.                     string response = "";
  40.  
  41.                     var body = ea.Body;
  42.  
  43.                     var message = Encoding.UTF8.GetString(body);
  44.                     int n = int.Parse(message);
  45.                     response = plusJeden(n).ToString();
  46.  
  47.                     Console.WriteLine("Wynik: 1 + {0} = {1}", message, response);
  48.                 };
  49.                 channel.BasicConsume(queueName, true, consumer);
  50.                 Console.ReadLine();
  51.  
  52.             }
  53.         }
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement