Skip to content

Instantly share code, notes, and snippets.

@mikeminutillo
Created December 13, 2016 03:39
Show Gist options
  • Save mikeminutillo/9adf3b7f0b507455ec6616d5a99ae8cb to your computer and use it in GitHub Desktop.
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.
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;
}
}
@mikeminutillo
Copy link
Author

To enable in an endpoint, call endpointConfig.EnableFeature<PublishHandledEventsAtStartup>();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment