-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from FoundatioFx/feature/rabbitmq7
Upgrade to RabbitMQ 7
- Loading branch information
Showing
13 changed files
with
372 additions
and
299 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM rabbitmq:3.10-management | ||
FROM rabbitmq:4.0.3-management | ||
|
||
COPY rabbitmq_delayed_message_exchange-3.10.0.ez /opt/rabbitmq/plugins | ||
COPY rabbitmq_delayed_message_exchange-4.0.2.ez /opt/rabbitmq/plugins | ||
RUN rabbitmq-plugins enable rabbitmq_delayed_message_exchange |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
238 changes: 146 additions & 92 deletions
238
src/Foundatio.RabbitMQ/Messaging/RabbitMQMessageBus.cs
Large diffs are not rendered by default.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
tests/Foundatio.RabbitMQ.Tests/Messaging/RabbitMqMessageBusDelayedExchangeTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using Xunit.Abstractions; | ||
|
||
namespace Foundatio.RabbitMQ.Tests.Messaging; | ||
|
||
public class RabbitMqMessageBusDelayedExchangeTests : RabbitMqMessageBusTestBase | ||
{ | ||
public RabbitMqMessageBusDelayedExchangeTests(ITestOutputHelper output) : base("amqp://localhost:5673", output) { } | ||
} |
203 changes: 203 additions & 0 deletions
203
tests/Foundatio.RabbitMQ.Tests/Messaging/RabbitMqMessageBusTestBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,203 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Foundatio.AsyncEx; | ||
using Foundatio.Messaging; | ||
using Foundatio.Tests.Extensions; | ||
using Foundatio.Tests.Messaging; | ||
using Microsoft.Extensions.Logging; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace Foundatio.RabbitMQ.Tests.Messaging; | ||
|
||
public abstract class RabbitMqMessageBusTestBase(string connectionString, ITestOutputHelper output) : MessageBusTestBase(output) | ||
{ | ||
private readonly string _topic = $"test_topic_{DateTime.UtcNow.Ticks}"; | ||
|
||
protected override IMessageBus GetMessageBus(Func<SharedMessageBusOptions, SharedMessageBusOptions> config = null) | ||
{ | ||
return new RabbitMQMessageBus(o => | ||
{ | ||
o.ConnectionString(connectionString); | ||
o.LoggerFactory(Log); | ||
|
||
config?.Invoke(o.Target); | ||
|
||
return o; | ||
}); | ||
} | ||
|
||
[Fact] | ||
public override Task CanUseMessageOptionsAsync() | ||
{ | ||
return base.CanUseMessageOptionsAsync(); | ||
} | ||
|
||
[Fact] | ||
public override Task CanSendMessageAsync() | ||
{ | ||
return base.CanSendMessageAsync(); | ||
} | ||
|
||
[Fact] | ||
public override Task CanHandleNullMessageAsync() | ||
{ | ||
return base.CanHandleNullMessageAsync(); | ||
} | ||
|
||
[Fact] | ||
public override Task CanSendDerivedMessageAsync() | ||
{ | ||
return base.CanSendDerivedMessageAsync(); | ||
} | ||
|
||
[Fact] | ||
public override Task CanSendMappedMessageAsync() | ||
{ | ||
return base.CanSendMappedMessageAsync(); | ||
} | ||
|
||
[Fact] | ||
public override Task CanSendDelayedMessageAsync() | ||
{ | ||
return base.CanSendDelayedMessageAsync(); | ||
} | ||
|
||
[Fact] | ||
public override Task CanSubscribeConcurrentlyAsync() | ||
{ | ||
return base.CanSubscribeConcurrentlyAsync(); | ||
} | ||
|
||
[Fact] | ||
public override Task CanReceiveMessagesConcurrentlyAsync() | ||
{ | ||
return base.CanReceiveMessagesConcurrentlyAsync(); | ||
} | ||
|
||
[Fact] | ||
public override Task CanSendMessageToMultipleSubscribersAsync() | ||
{ | ||
return base.CanSendMessageToMultipleSubscribersAsync(); | ||
} | ||
|
||
[Fact] | ||
public override Task CanTolerateSubscriberFailureAsync() | ||
{ | ||
return base.CanTolerateSubscriberFailureAsync(); | ||
} | ||
|
||
[Fact] | ||
public override Task WillOnlyReceiveSubscribedMessageTypeAsync() | ||
{ | ||
return base.WillOnlyReceiveSubscribedMessageTypeAsync(); | ||
} | ||
|
||
[Fact] | ||
public override Task WillReceiveDerivedMessageTypesAsync() | ||
{ | ||
return base.WillReceiveDerivedMessageTypesAsync(); | ||
} | ||
|
||
[Fact] | ||
public override Task CanSubscribeToAllMessageTypesAsync() | ||
{ | ||
return base.CanSubscribeToAllMessageTypesAsync(); | ||
} | ||
|
||
[Fact] | ||
public override Task CanSubscribeToRawMessagesAsync() | ||
{ | ||
return base.CanSubscribeToRawMessagesAsync(); | ||
} | ||
|
||
[Fact] | ||
public override Task CanCancelSubscriptionAsync() | ||
{ | ||
return base.CanCancelSubscriptionAsync(); | ||
} | ||
|
||
[Fact] | ||
public override Task WontKeepMessagesWithNoSubscribersAsync() | ||
{ | ||
return base.WontKeepMessagesWithNoSubscribersAsync(); | ||
} | ||
|
||
[Fact] | ||
public override Task CanReceiveFromMultipleSubscribersAsync() | ||
{ | ||
return base.CanReceiveFromMultipleSubscribersAsync(); | ||
} | ||
|
||
[Fact] | ||
public override void CanDisposeWithNoSubscribersOrPublishers() | ||
{ | ||
base.CanDisposeWithNoSubscribersOrPublishers(); | ||
} | ||
|
||
[Fact] | ||
public async Task CanPersistAndNotLoseMessages() | ||
{ | ||
var messageBus1 = new RabbitMQMessageBus(o => o | ||
.ConnectionString(connectionString) | ||
.LoggerFactory(Log) | ||
.SubscriptionQueueName($"{_topic}-offline") | ||
.IsSubscriptionQueueExclusive(false) | ||
.SubscriptionQueueAutoDelete(false) | ||
.AcknowledgementStrategy(AcknowledgementStrategy.Automatic)); | ||
|
||
var countdownEvent = new AsyncCountdownEvent(1); | ||
var cts = new CancellationTokenSource(); | ||
await messageBus1.SubscribeAsync<SimpleMessageA>(msg => | ||
{ | ||
_logger.LogInformation("[Subscriber1] Got message: {Message}", msg.Data); | ||
countdownEvent.Signal(); | ||
}, cts.Token); | ||
|
||
await messageBus1.PublishAsync(new SimpleMessageA { Data = "Audit message 1" }); | ||
await countdownEvent.WaitAsync(TimeSpan.FromSeconds(5)); | ||
Assert.Equal(0, countdownEvent.CurrentCount); | ||
await cts.CancelAsync(); | ||
|
||
await messageBus1.PublishAsync(new SimpleMessageA { Data = "Audit message 2" }); | ||
|
||
cts = new CancellationTokenSource(); | ||
countdownEvent.AddCount(1); | ||
await messageBus1.SubscribeAsync<SimpleMessageA>(msg => | ||
{ | ||
_logger.LogInformation("[Subscriber2] Got message: {Message}", msg.Data); | ||
countdownEvent.Signal(); | ||
}, cts.Token); | ||
await countdownEvent.WaitAsync(TimeSpan.FromSeconds(5)); | ||
Assert.Equal(0, countdownEvent.CurrentCount); | ||
await cts.CancelAsync(); | ||
|
||
await messageBus1.PublishAsync(new SimpleMessageA { Data = "Audit offline message 1" }); | ||
await messageBus1.PublishAsync(new SimpleMessageA { Data = "Audit offline message 2" }); | ||
await messageBus1.PublishAsync(new SimpleMessageA { Data = "Audit offline message 3" }); | ||
|
||
await messageBus1.DisposeAsync(); | ||
|
||
var messageBus2 = new RabbitMQMessageBus(o => o | ||
.ConnectionString(connectionString) | ||
.LoggerFactory(Log) | ||
.SubscriptionQueueName($"{_topic}-offline") | ||
.IsSubscriptionQueueExclusive(false) | ||
.SubscriptionQueueAutoDelete(false) | ||
.AcknowledgementStrategy(AcknowledgementStrategy.Automatic)); | ||
|
||
cts = new CancellationTokenSource(); | ||
countdownEvent.AddCount(4); | ||
await messageBus2.SubscribeAsync<SimpleMessageA>(msg => | ||
{ | ||
_logger.LogInformation("[Subscriber3] Got message: {Message}", msg.Data); | ||
countdownEvent.Signal(); | ||
}, cts.Token); | ||
await messageBus2.PublishAsync(new SimpleMessageA { Data = "Another audit message 4" }); | ||
await countdownEvent.WaitAsync(TimeSpan.FromSeconds(5)); | ||
Assert.Equal(0, countdownEvent.CurrentCount); | ||
|
||
await messageBus2.DisposeAsync(); | ||
} | ||
} |
Oops, something went wrong.