Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using RabbitMQ.Client;
- using RabbitMQ.Client.Events;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace rabbit2
- {
- class Program
- {
- private static int plusJeden(int n)
- {
- return n + 1;
- }
- 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())
- {
- channel.ExchangeDeclare("top_rout", "topic");
- var queueName = channel.QueueDeclare().QueueName;
- channel.QueueBind(queueName, "top_rout", "#.#.rabbit");
- var consumer = new EventingBasicConsumer(channel);
- Console.WriteLine("Odbiorca jest aktywny");
- consumer.Received += (model, ea) =>
- {
- string response = "";
- var body = ea.Body;
- var message = Encoding.UTF8.GetString(body);
- int n = int.Parse(message);
- response = plusJeden(n).ToString();
- Console.WriteLine("Wynik: 1 + {0} = {1}", message, response);
- };
- channel.BasicConsume(queueName, true, consumer);
- Console.ReadLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement