Advertisement
Guest User

Untitled

a guest
Nov 11th, 2018
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.47 KB | None | 0 0
  1.  
  2.     public class RabbitMqConsumer : IRabbitMqConsumer
  3.     {
  4.         private string _queueName = "uservote";
  5.         private IConnection _rabbitMqConnection;
  6.         private IModel _queueChannel;
  7.  
  8.         public RabbitMqConsumer()
  9.         {
  10.             var factory = Helpers.CreateConnectionFactory();
  11.  
  12.             _rabbitMqConnection = factory.CreateConnection();
  13.             _queueChannel = _rabbitMqConnection.CreateModel();
  14.            
  15.             _queueChannel.QueueDeclare(queue: _queueName,
  16.                     durable: false,
  17.                     exclusive: false,
  18.                     autoDelete: false,
  19.                     arguments: null);
  20.  
  21.             var consumer = new EventingBasicConsumer(_queueChannel);
  22.             //consumer.Received += Consume;
  23.  
  24.             _queueChannel.BasicConsume(queue: _queueName,
  25.                                     autoAck: true,
  26.                                     consumer: consumer);
  27.         }
  28.  
  29.         private void Consume(object model, BasicDeliverEventArgs eventArgs)
  30.         {
  31.  
  32.         }
  33.  
  34.         public void Dispose()
  35.         {
  36.             _queueChannel.Close();
  37.             _rabbitMqConnection.Close();
  38.         }
  39.     }
  40.  
  41.  
  42.  
  43. // Helpers
  44.         public static ConnectionFactory CreateConnectionFactory()
  45.         {
  46.             return new ConnectionFactory
  47.             {
  48.                 HostName = "localhost",
  49.                 Password = "guest",
  50.                 UserName = "guest"
  51.             };
  52.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement