File tree Expand file tree Collapse file tree 5 files changed +62
-0
lines changed
Transports/RabbitMQ/Wolverine.RabbitMQ.Tests Expand file tree Collapse file tree 5 files changed +62
-0
lines changed Original file line number Diff line number Diff line change @@ -162,5 +162,15 @@ This option does a couple things:
162162* Sets any local execution of the listener's internal, local queue to be strictly sequential and only process messages with
163163 a single thread
164164
165+ ## Disabling All External Listeners
165166
167+ In some cases, you may want to disable all message processing for messages received from external
168+ transports like Rabbit MQ or AWS SQS. To do that, simply set:
169+
170+ snippet: sample_disable_all_listeners
171+
172+ The original use case for this flag was a command line tool that needed to publish messages to
173+ a system through Rabbit MQ then exit. Having that process also trying to publish messages received
174+ from Rabbit MQ kept the command line tool from quitting quickly as Wolverine had to "drain" ongoing
175+ work. For that kind of tool, we recommend this setting.
166176
Original file line number Diff line number Diff line change @@ -27,6 +27,12 @@ public void publish_agent_events_should_be_false_by_default()
2727 new WolverineOptions ( ) . Policies . PublishAgentEvents . ShouldBeFalse ( ) ;
2828 }
2929
30+ [ Fact ]
31+ public void do_not_disable_external_listeners_by_default ( )
32+ {
33+ new WolverineOptions ( ) . DisableAllExternalListeners . ShouldBeFalse ( ) ;
34+ }
35+
3036 [ Fact ]
3137 public void default_dead_letter_queue_behavior_is_discard ( )
3238 {
Original file line number Diff line number Diff line change 1+ using Microsoft . Extensions . Hosting ;
2+ using Shouldly ;
3+ using Wolverine . ComplianceTests ;
4+ using Wolverine . Tracking ;
5+ using Xunit ;
6+
7+ namespace Wolverine . RabbitMQ . Tests ;
8+
9+ public class disable_external_listeners
10+ {
11+ [ Fact ]
12+ public async Task listeners_are_not_active ( )
13+ {
14+ using var host = await Host . CreateDefaultBuilder ( )
15+
16+ #region sample_disable_all_listeners
17+
18+ . UseWolverine ( opts =>
19+ {
20+ // This will disable all message listening to
21+ // external message brokers
22+ opts . DisableAllExternalListeners = true ;
23+
24+ opts . DisableConventionalDiscovery ( ) ;
25+
26+ // This could never, ever work
27+ opts . UseRabbitMq ( ) . AutoProvision ( ) ;
28+ opts . ListenToRabbitQueue ( "incoming" ) ;
29+ } ) . StartAsync ( ) ;
30+
31+ #endregion
32+
33+ var activeListeners = host . GetRuntime ( ) . Endpoints . ActiveListeners ( ) . ToArray ( ) ;
34+ activeListeners
35+ . Any ( ) . ShouldBeFalse ( ) ;
36+ }
37+ }
Original file line number Diff line number Diff line change @@ -237,6 +237,8 @@ public IReadOnlyList<Endpoint> LeaderPinnedListeners()
237237
238238 public async Task StartListenersAsync ( )
239239 {
240+ if ( _options . DisableAllExternalListeners ) return ;
241+
240242 var listeningEndpoints = _options . Transports . SelectMany ( x => x . Endpoints ( ) )
241243 . Where ( x => x is not LocalQueue )
242244 . Where ( x => x . ShouldAutoStartAsListener ( _options . Durability ) ) ;
Original file line number Diff line number Diff line change @@ -294,6 +294,13 @@ public AutoCreate AutoBuildMessageStorageOnStartup
294294 /// to latch all outgoing message sending
295295 /// </summary>
296296 internal bool ExternalTransportsAreStubbed { get ; set ; }
297+
298+ /// <summary>
299+ /// Should all listeners for external transports be disabled in
300+ /// this process? You may want to use this for command line applications
301+ /// that publish outbound messages
302+ /// </summary>
303+ public bool DisableAllExternalListeners { get ; set ; }
297304
298305 [ IgnoreDescription ]
299306 internal LocalTransport LocalRouting => Transports . GetOrCreate < LocalTransport > ( ) ;
You can’t perform that action at this time.
0 commit comments