Merge pull request #2 from TimetableDesigner/features/queue_builder_separation

queue and builder separation
This commit is contained in:
2026-01-18 20:55:15 +01:00
committed by GitHub
Unverified
3 changed files with 44 additions and 16 deletions

View File

@@ -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; } = "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 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 = port,
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));
}
}

View File

@@ -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 }
};
}

View File

@@ -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>