Created
December 13, 2016 03:39
-
-
Save mikeminutillo/9adf3b7f0b507455ec6616d5a99ae8cb to your computer and use it in GitHub Desktop.
NServiceBus 6 feature. When enabled in an endpoint this feature will report all event types that can be handled to the console at startup.
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
class PublishHandledEventsAtStartup : Feature | |
{ | |
protected override void Setup(FeatureConfigurationContext context) | |
{ | |
var conventions = context.Settings.Get<Conventions>(); | |
context.RegisterStartupTask(b => | |
{ | |
var handlerRegistry = b.Build<MessageHandlerRegistry>(); | |
return new PublishedHandledEventsToConsole(handlerRegistry.GetMessageTypes().Where(conventions.IsEventType)); | |
}); | |
} | |
class PublishedHandledEventsToConsole : FeatureStartupTask | |
{ | |
private readonly IEnumerable<Type> messageTypesHandled; | |
public PublishedHandledEventsToConsole(IEnumerable<Type> messageTypesHandled) | |
{ | |
this.messageTypesHandled = messageTypesHandled; | |
} | |
protected override Task OnStart(IMessageSession session) | |
{ | |
foreach (var messageTypeHandled in messageTypesHandled) | |
{ | |
Console.WriteLine(messageTypeHandled); | |
} | |
return Task.CompletedTask; | |
} | |
protected override Task OnStop(IMessageSession session) => Task.CompletedTask; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
To enable in an endpoint, call
endpointConfig.EnableFeature<PublishHandledEventsAtStartup>();