8 Commits
1.0.0 ... 1.0.3

4 changed files with 77 additions and 16 deletions

21
LICENSE Normal file
View 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.

View File

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

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

@@ -4,11 +4,23 @@
<TargetFramework>net10.0</TargetFramework> <TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <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> </PropertyGroup>
<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>
<None Update="icon.png">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>
</Project> </Project>