Compare commits
6 Commits
@@ -3,29 +3,36 @@ using RabbitMQ.Client;
|
|||||||
|
|
||||||
namespace TimetableDesigner.Backend.Events.Providers.RabbitMQ;
|
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
|
ConnectionFactory factory = new ConnectionFactory
|
||||||
{
|
{
|
||||||
HostName = Hostname,
|
HostName = hostname,
|
||||||
Port = Port,
|
Port = int.Parse(port),
|
||||||
UserName = Username,
|
UserName = username,
|
||||||
Password = Password,
|
Password = password,
|
||||||
};
|
};
|
||||||
|
|
||||||
Task<IConnection> createConnectionTask = factory.CreateConnectionAsync();
|
Task<IConnection> createConnectionTask = factory.CreateConnectionAsync();
|
||||||
createConnectionTask.Wait();
|
createConnectionTask.Wait();
|
||||||
services.AddSingleton(createConnectionTask.Result);
|
services.AddSingleton(createConnectionTask.Result);
|
||||||
services.AddSingleton<IEventQueuePublisher, RabbitMQEventQueuePublisher>(sp => new RabbitMQEventQueuePublisher(sp.GetRequiredService<IConnection>(), ExchangeName));
|
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<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>
|
<ItemGroup>
|
||||||
<PackageReference Include="RabbitMQ.Client" Version="7.2.0" />
|
<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>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
Reference in New Issue
Block a user