Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
# Changelog
## [5.0.0] - 2026-05-12
### *Changes (Breaking)*
- Target .NET 10
- Add optional additionalBindings parameter to RabbitChannelConfiguration, allowing a consumer queue to bind to multiple external exchanges with specific routing keys
- Add ExchangeBinding record type
## [4.0.1] - 2026-04-02
### *Changes
- Add optional exchangeType parameter to RabbitChannelConfiguration
Expand Down
3 changes: 3 additions & 0 deletions src/ExchangeBinding.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
namespace Linn.Common.Messaging.RabbitMQ;

public record ExchangeBinding(string ExchangeName, string[] RoutingKeys);
4 changes: 2 additions & 2 deletions src/Linn.Common.Messaging.RabbitMQ.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Description>Utilities for requesting data from other (proxy) services.</Description>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<AssemblyName>Linn.Common.Messaging.RabbitMQ</AssemblyName>
<PackageId>Linn.Common.Messaging.RabbitMQ</PackageId>
<Version>4.0.1</Version>
<Version>5.0.0</Version>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
Expand Down
20 changes: 19 additions & 1 deletion src/RabbitChannelConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
string? dlxName = null,
bool createProducerChannel = true,
bool createConsumerChannel = true,
string exchangeType = ExchangeType.Direct)
string exchangeType = ExchangeType.Direct,
ExchangeBinding[]? additionalBindings = null)
: IAsyncDisposable
{
private readonly string dlqName = string.IsNullOrEmpty(dlqName) ? queueName : dlqName;
Expand All @@ -33,10 +34,10 @@
{
var factory = new ConnectionFactory
{
HostName = ConfigurationManager.Configuration["RABBIT_SERVER"],

Check warning on line 37 in src/RabbitChannelConfiguration.cs

View workflow job for this annotation

GitHub Actions / build-and-publish

Possible null reference assignment.

Check warning on line 37 in src/RabbitChannelConfiguration.cs

View workflow job for this annotation

GitHub Actions / build-and-publish

Possible null reference assignment.
UserName = ConfigurationManager.Configuration["RABBIT_USERNAME"],

Check warning on line 38 in src/RabbitChannelConfiguration.cs

View workflow job for this annotation

GitHub Actions / build-and-publish

Possible null reference assignment.

Check warning on line 38 in src/RabbitChannelConfiguration.cs

View workflow job for this annotation

GitHub Actions / build-and-publish

Possible null reference assignment.
Password = ConfigurationManager.Configuration["RABBIT_PASSWORD"],

Check warning on line 39 in src/RabbitChannelConfiguration.cs

View workflow job for this annotation

GitHub Actions / build-and-publish

Possible null reference assignment.

Check warning on line 39 in src/RabbitChannelConfiguration.cs

View workflow job for this annotation

GitHub Actions / build-and-publish

Possible null reference assignment.
Port = int.Parse(ConfigurationManager.Configuration["RABBIT_PORT"])

Check warning on line 40 in src/RabbitChannelConfiguration.cs

View workflow job for this annotation

GitHub Actions / build-and-publish

Possible null reference argument for parameter 's' in 'int int.Parse(string s)'.

Check warning on line 40 in src/RabbitChannelConfiguration.cs

View workflow job for this annotation

GitHub Actions / build-and-publish

Possible null reference argument for parameter 's' in 'int int.Parse(string s)'.
};

this.Connection = await factory.CreateConnectionAsync(cancellationToken);
Expand Down Expand Up @@ -99,7 +100,7 @@
durable: true,
exclusive: false,
autoDelete: false,
arguments: args,

Check warning on line 103 in src/RabbitChannelConfiguration.cs

View workflow job for this annotation

GitHub Actions / build-and-publish

Argument of type 'Dictionary<string, object>' cannot be used for parameter 'arguments' of type 'IDictionary<string, object?>' in 'Task<QueueDeclareOk> IChannel.QueueDeclareAsync(string queue, bool durable, bool exclusive, bool autoDelete, IDictionary<string, object?>? arguments = null, bool passive = false, bool noWait = false, CancellationToken cancellationToken = default(CancellationToken))' due to differences in the nullability of reference types.

Check warning on line 103 in src/RabbitChannelConfiguration.cs

View workflow job for this annotation

GitHub Actions / build-and-publish

Argument of type 'Dictionary<string, object>' cannot be used for parameter 'arguments' of type 'IDictionary<string, object?>' in 'Task<QueueDeclareOk> IChannel.QueueDeclareAsync(string queue, bool durable, bool exclusive, bool autoDelete, IDictionary<string, object?>? arguments = null, bool passive = false, bool noWait = false, CancellationToken cancellationToken = default(CancellationToken))' due to differences in the nullability of reference types.
cancellationToken: cancellationToken);

foreach (var routingKey in routingKeys)
Expand All @@ -112,6 +113,23 @@
noWait: false,
cancellationToken: cancellationToken);
}

if (additionalBindings != null)
{
foreach (var binding in additionalBindings)
{
foreach (var routingKey in binding.RoutingKeys)
{
await setupChannel.QueueBindAsync(
queue: $"{queueName}.q",
exchange: $"{binding.ExchangeName}.x",
routingKey: routingKey,
arguments: null,
noWait: false,
cancellationToken: cancellationToken);
}
}
}
}
}

Expand Down
Loading