Compare commits
8 Commits
21
LICENSE
Normal file
21
LICENSE
Normal file
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2026 Mateusz Skoczek
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -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 = 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));
|
||||
}
|
||||
}
|
||||
@@ -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 }
|
||||
};
|
||||
}
|
||||
@@ -4,11 +4,23 @@
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<Version />
|
||||
<Title>TimetableDesigner.Backend.Events.Providers.RabbitMQ</Title>
|
||||
<Authors>Mateusz Skoczek</Authors>
|
||||
<PackageProjectUrl>https://github.com/TimetableDesigner/TimetableDesigner.Backend.Events.Providers.RabbitMQ</PackageProjectUrl>
|
||||
<PackageIcon>icon.png</PackageIcon>
|
||||
<RepositoryUrl>https://github.com/TimetableDesigner/TimetableDesigner.Backend.Events.Providers.RabbitMQ</RepositoryUrl>
|
||||
</PropertyGroup>
|
||||
|
||||
<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>
|
||||
<None Update="icon.png">
|
||||
<Pack>True</Pack>
|
||||
<PackagePath></PackagePath>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user