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 RabbitLab
- {
- class Program
- {
- static void Main(string[] args)
- {
- var factory = new ConnectionFactory()
- {
- UserName = "amivnqqc",
- VirtualHost = "amivnqqc",
- HostName = "bulldog.rmq.cloudamqp.com",
- Password = "WyPz_1Vl1KoR3lUvzgZfm7IhWXWYdnlE"
- };
- using (var connection = factory.CreateConnection())
- using (var channel = connection.CreateModel())
- {
- channel.QueueDeclare("ksr_queue", false, false, false, null);
- string replyQueueName = channel.QueueDeclare().QueueName;
- string message = "Wiadomość testowa";
- var body = Encoding.UTF8.GetBytes(message);
- IBasicProperties props = channel.CreateBasicProperties();
- props.ReplyTo = replyQueueName;
- var corrId = Guid.NewGuid().ToString();
- props.CorrelationId = corrId;
- var replyConsumer = new EventingBasicConsumer(channel);
- replyConsumer.Received += (mode, ea) =>
- {
- if (ea.BasicProperties.CorrelationId == corrId)
- {
- Console.WriteLine("[{0}][{1}] Przyjęto zadanie", corrId, Encoding.UTF8.GetString(ea.Body));
- }
- };
- channel.BasicConsume(replyQueueName, true, replyConsumer);
- channel.BasicPublish("", "ksr_queue", props, body);
- Console.ReadKey();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement