Compare commits
6 Commits
@@ -3,29 +3,36 @@ using RabbitMQ.Client;
|
||||
|
||||
namespace TimetableDesigner.Backend.Events.Providers.RabbitMQ;
|
||||
|
||||
public class RabbitMQEventQueue : EventQueue
|
||||
public class RabbitMQEventQueue : EventQueue<RabbitMQEventQueue>
|
||||
{
|
||||
public string Hostname { get; set; } = null!;
|
||||
public int Port { get; set; }
|
||||
public string Username { get; set; } = null!;
|
||||
public string Password { get; set; } = null!;
|
||||
public string ExchangeName { get; set; } = null!;
|
||||
public string QueuePrefix { get; set; } = null!;
|
||||
|
||||
public override void Setup(IServiceCollection services)
|
||||
protected override void Setup(IServiceCollection services, IDictionary<string, string> connectionParameters)
|
||||
{
|
||||
if (!connectionParameters.TryGetValue("Hostname", out string hostname))
|
||||
{
|
||||
hostname = "localhost";
|
||||
}
|
||||
if (!connectionParameters.TryGetValue("Port", out string port))
|
||||
{
|
||||
port = "5672";
|
||||
}
|
||||
string username = connectionParameters["Username"];
|
||||
string password = connectionParameters["Password"];
|
||||
string exchangeName = connectionParameters["ExchangeName"];
|
||||
string queuePrefix = connectionParameters["QueuePrefix"];
|
||||
|
||||
ConnectionFactory factory = new ConnectionFactory
|
||||
{
|
||||
HostName = Hostname,
|
||||
Port = Port,
|
||||
UserName = Username,
|
||||
Password = Password,
|
||||
HostName = hostname,
|
||||
Port = int.Parse(port),
|
||||
UserName = username,
|
||||
Password = password,
|
||||
};
|
||||
|
||||
|
||||
Task<IConnection> createConnectionTask = factory.CreateConnectionAsync();
|
||||
createConnectionTask.Wait();
|
||||
services.AddSingleton(createConnectionTask.Result);
|
||||
services.AddSingleton<IEventQueuePublisher, RabbitMQEventQueuePublisher>(sp => new RabbitMQEventQueuePublisher(sp.GetRequiredService<IConnection>(), ExchangeName));
|
||||
services.AddSingleton<IEventQueueSubscriber, RabbitMQEventQueueSubscriber>(sp => new RabbitMQEventQueueSubscriber(sp.GetRequiredService<IConnection>(), ExchangeName, QueuePrefix));
|
||||
services.AddSingleton<IEventQueuePublisher, RabbitMQEventQueuePublisher>(sp => new RabbitMQEventQueuePublisher(sp.GetRequiredService<IConnection>(), exchangeName));
|
||||
services.AddSingleton<IEventQueueSubscriber, RabbitMQEventQueueSubscriber>(sp => new RabbitMQEventQueueSubscriber(sp.GetRequiredService<IConnection>(), exchangeName, queuePrefix));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
namespace TimetableDesigner.Backend.Events.Providers.RabbitMQ;
|
||||
|
||||
public class RabbitMQEventQueueBuilder : EventQueueBuilder<RabbitMQEventQueue>
|
||||
{
|
||||
public string Hostname { get; set; } = "localhost";
|
||||
public int Port { get; set; } = 5672;
|
||||
public string Username { get; set; } = null!;
|
||||
public string Password { get; set; } = null!;
|
||||
public string ExchangeName { get; set; } = null!;
|
||||
public string QueuePrefix { get; set; } = null!;
|
||||
|
||||
public override IDictionary<string, string> GetConnectionParameters() => new Dictionary<string, string>()
|
||||
{
|
||||
{ nameof(Hostname), Hostname },
|
||||
{ nameof(Port), Port.ToString() },
|
||||
{ nameof(Username), Username },
|
||||
{ nameof(Password), Password },
|
||||
{ nameof(ExchangeName), ExchangeName },
|
||||
{ nameof(QueuePrefix), QueuePrefix }
|
||||
};
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="RabbitMQ.Client" Version="7.2.0" />
|
||||
<PackageReference Include="timetabledesigner.backend.events" Version="1.1.1" />
|
||||
<PackageReference Include="timetabledesigner.backend.events" Version="1.1.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
Reference in New Issue
Block a user