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
10 changes: 10 additions & 0 deletions docs/guide/messaging/listeners.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,5 +162,15 @@ This option does a couple things:
* Sets any local execution of the listener's internal, local queue to be strictly sequential and only process messages with
a single thread

## Disabling All External Listeners

In some cases, you may want to disable all message processing for messages received from external
transports like Rabbit MQ or AWS SQS. To do that, simply set:

snippet: sample_disable_all_listeners

The original use case for this flag was a command line tool that needed to publish messages to
a system through Rabbit MQ then exit. Having that process also trying to publish messages received
from Rabbit MQ kept the command line tool from quitting quickly as Wolverine had to "drain" ongoing
work. For that kind of tool, we recommend this setting.

6 changes: 6 additions & 0 deletions src/Testing/CoreTests/WolverineOptionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ public void publish_agent_events_should_be_false_by_default()
new WolverineOptions().Policies.PublishAgentEvents.ShouldBeFalse();
}

[Fact]
public void do_not_disable_external_listeners_by_default()
{
new WolverineOptions().DisableAllExternalListeners.ShouldBeFalse();
}

[Fact]
public void default_dead_letter_queue_behavior_is_discard()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Microsoft.Extensions.Hosting;
using Shouldly;
using Wolverine.ComplianceTests;
using Wolverine.Tracking;
using Xunit;

namespace Wolverine.RabbitMQ.Tests;

public class disable_external_listeners
{
[Fact]
public async Task listeners_are_not_active()
{
using var host = await Host.CreateDefaultBuilder()

#region sample_disable_all_listeners

.UseWolverine(opts =>
{
// This will disable all message listening to
// external message brokers
opts.DisableAllExternalListeners = true;

opts.DisableConventionalDiscovery();

// This could never, ever work
opts.UseRabbitMq().AutoProvision();
opts.ListenToRabbitQueue("incoming");
}).StartAsync();

#endregion

var activeListeners = host.GetRuntime().Endpoints.ActiveListeners().ToArray();
activeListeners
.Any().ShouldBeFalse();
}
}
2 changes: 2 additions & 0 deletions src/Wolverine/Configuration/EndpointCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ public IReadOnlyList<Endpoint> LeaderPinnedListeners()

public async Task StartListenersAsync()
{
if (_options.DisableAllExternalListeners) return;

var listeningEndpoints = _options.Transports.SelectMany(x => x.Endpoints())
.Where(x => x is not LocalQueue)
.Where(x => x.ShouldAutoStartAsListener(_options.Durability));
Expand Down
7 changes: 7 additions & 0 deletions src/Wolverine/WolverineOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,13 @@ public AutoCreate AutoBuildMessageStorageOnStartup
/// to latch all outgoing message sending
/// </summary>
internal bool ExternalTransportsAreStubbed { get; set; }

/// <summary>
/// Should all listeners for external transports be disabled in
/// this process? You may want to use this for command line applications
/// that publish outbound messages
/// </summary>
public bool DisableAllExternalListeners { get; set; }

[IgnoreDescription]
internal LocalTransport LocalRouting => Transports.GetOrCreate<LocalTransport>();
Expand Down
Loading