using RabbitMQ.Client;
using System;
namespace RabbitMQ.Implementations
{
public abstract class RabbitMQClient : IDisposable
{
protected IConnection _connection;
protected IModel _channel;
public RabbitMQClient()
{
var username = Environment.GetEnvironmentVariable("AMQP_USERNAME") ?? throw new Exception("Env var AMQP_USERNAME is not defined.");
var password = Environment.GetEnvironmentVariable("AMQP_PASSWORD") ?? throw new Exception("Env var AMQP_PASSWORD is not defined.");
var host = Environment.GetEnvironmentVariable("AMQP_HOST") ?? throw new Exception("Env var AMQP_HOST is not defined.");
var factory = new ConnectionFactory
{
Uri = new Uri($"amqp://{username}:{password}@{host}")
};
_connection = factory.CreateConnection();
_channel = _connection.CreateModel();
}
public void Dispose()
{
_connection.Dispose();
_channel.Dispose();
}
}
}
using RabbitMQ.Client;
using System;
namespace RabbitMQ.Implementations
{
public abstract class RabbitMQClient : IDisposable
{
protected IConnection _connection;
protected IModel _channel;
public RabbitMQClient()
{
var username = Environment.GetEnvironmentVariable("AMQP_USERNAME") ?? throw new Exception("Env var AMQP_USERNAME is not defined.");
var password = Environment.GetEnvironmentVariable("AMQP_PASSWORD") ?? throw new Exception("Env var AMQP_PASSWORD is not defined.");
var host = Environment.GetEnvironmentVariable("AMQP_HOST") ?? throw new Exception("Env var AMQP_HOST is not defined.");
var factory = new ConnectionFactory
{
Uri = new Uri($"amqp://{username}:{password}@{host}")
};
_connection = factory.CreateConnection();
_channel = _connection.CreateModel();
}
public void Dispose()
{
_connection.Dispose();
_channel.Dispose();
}
}
}