Skip to content

Commit

Permalink
Updated MaxAge to properly format the queue attribute when configurin…
Browse files Browse the repository at this point in the history
…g a RabbitMQ stream
  • Loading branch information
phatboyg committed Jun 27, 2024
1 parent 3e8b049 commit e11c12a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class RabbitMqStreamConfigurator :
IRabbitMqStreamConfigurator
{
static readonly DateTimeTypeConverter _dateTimeConverter = new DateTimeTypeConverter();
static readonly TimeSpanTypeConverter _timeSpanConverter = new TimeSpanTypeConverter();

readonly RabbitMqReceiveSettings _settings;

Expand All @@ -24,7 +25,20 @@ public long MaxLength

public TimeSpan MaxAge
{
set => _settings.QueueArguments["x-max-age"] = value;
set
{
string? text = null;

Check warning on line 30 in src/Transports/MassTransit.RabbitMqTransport/RabbitMqTransport/Configuration/RabbitMqStreamConfigurator.cs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 30 in src/Transports/MassTransit.RabbitMqTransport/RabbitMqTransport/Configuration/RabbitMqStreamConfigurator.cs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 30 in src/Transports/MassTransit.RabbitMqTransport/RabbitMqTransport/Configuration/RabbitMqStreamConfigurator.cs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 30 in src/Transports/MassTransit.RabbitMqTransport/RabbitMqTransport/Configuration/RabbitMqStreamConfigurator.cs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 30 in src/Transports/MassTransit.RabbitMqTransport/RabbitMqTransport/Configuration/RabbitMqStreamConfigurator.cs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 30 in src/Transports/MassTransit.RabbitMqTransport/RabbitMqTransport/Configuration/RabbitMqStreamConfigurator.cs

View workflow job for this annotation

GitHub Actions / Build (ubuntu-latest)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 30 in src/Transports/MassTransit.RabbitMqTransport/RabbitMqTransport/Configuration/RabbitMqStreamConfigurator.cs

View workflow job for this annotation

GitHub Actions / Transports: RabbitMQ

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 30 in src/Transports/MassTransit.RabbitMqTransport/RabbitMqTransport/Configuration/RabbitMqStreamConfigurator.cs

View workflow job for this annotation

GitHub Actions / Build (windows-latest)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 30 in src/Transports/MassTransit.RabbitMqTransport/RabbitMqTransport/Configuration/RabbitMqStreamConfigurator.cs

View workflow job for this annotation

GitHub Actions / Build (windows-latest)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 30 in src/Transports/MassTransit.RabbitMqTransport/RabbitMqTransport/Configuration/RabbitMqStreamConfigurator.cs

View workflow job for this annotation

GitHub Actions / Build (windows-latest)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 30 in src/Transports/MassTransit.RabbitMqTransport/RabbitMqTransport/Configuration/RabbitMqStreamConfigurator.cs

View workflow job for this annotation

GitHub Actions / Build (windows-latest)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 30 in src/Transports/MassTransit.RabbitMqTransport/RabbitMqTransport/Configuration/RabbitMqStreamConfigurator.cs

View workflow job for this annotation

GitHub Actions / Build (windows-latest)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 30 in src/Transports/MassTransit.RabbitMqTransport/RabbitMqTransport/Configuration/RabbitMqStreamConfigurator.cs

View workflow job for this annotation

GitHub Actions / Build (windows-latest)

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
if (value.TotalDays >= 1)
text = $"{value.TotalDays:F0}D";
else if (value.TotalHours >= 1)
text = $"{value.TotalHours:F0}h";
else if (value.TotalMinutes >= 1)
text = $"{value.TotalMinutes:F0}m";
else if (value.TotalSeconds >= 1)
text = $"{value.TotalSeconds:F0}s";

_settings.QueueArguments["x-max-age"] = text;
}
}

public long MaxSegmentSize
Expand Down
4 changes: 3 additions & 1 deletion tests/MassTransit.RabbitMqTransport.Tests/Stream_Specs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ protected override void ConfigureConsumer(IReceiveEndpointConfigurator endpointC

if (endpointConfigurator is IRabbitMqReceiveEndpointConfigurator rmq)
{
rmq.Stream("consumer-tag", s =>
rmq.Stream("main-consumer", s =>
{
s.MaxAge = TimeSpan.FromDays(14);

s.FromFirst();
});
}
Expand Down

0 comments on commit e11c12a

Please sign in to comment.