Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using RabbitMQ;
- using RabbitMQ.Client;
- using RabbitMQ.Client.Events;
- namespace Producent
- {
- class Program
- {
- static void Main(string[] args)
- {
- var factory = new ConnectionFactory()
- {
- UserName = "guest",
- Password = "guest",
- HostName = "localhost",
- VirtualHost = "103057"
- };
- var connection = factory.CreateConnection();
- var channel = connection.CreateModel();
- string message = "my message";
- var body = Encoding.UTF8.GetBytes(message);
- IBasicProperties prop = channel.CreateBasicProperties();
- prop.Persistent = true;
- // ZAD 3
- // consume response from consumer
- string replyQueueName = channel.QueueDeclare().QueueName;
- EventingBasicConsumer consumer = new EventingBasicConsumer(channel);
- channel.BasicConsume(replyQueueName, true, consumer);
- // required for response
- prop.ReplyTo = replyQueueName;
- var corrId = Guid.NewGuid().ToString();
- prop.CorrelationId = corrId;
- for (int i = 0; i < 50; i++)
- {
- channel.BasicPublish("", "message_queue", prop, body);
- }
- Thread.Sleep(2000);
- consumer.Received += (model, ea) =>
- {
- if (ea.BasicProperties.CorrelationId == corrId)
- {
- Console.Write("\n{0}\n", Encoding.UTF8.GetString(ea.Body), ConsoleColor.Blue);
- }
- };
- // ZAD 3
- Console.ReadKey();
- channel.Close();
- connection.Close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement