Skip to content

Instantly share code, notes, and snippets.

@mikeminutillo
Last active August 11, 2016 03:40
Show Gist options
  • Save mikeminutillo/35a2f5f2732c152ead8d94ca439cebbd to your computer and use it in GitHub Desktop.
Save mikeminutillo/35a2f5f2732c152ead8d94ca439cebbd to your computer and use it in GitHub Desktop.
NServiceBus v5 Pipeline Inspector
public class PipelineInspector : IWantToRunWhenBusStartsAndStops
{
private readonly ReadOnlySettings settings;
public PipelineInspector(ReadOnlySettings settings)
{
this.settings = settings;
}
public void Start()
{
var pipelineModificationsType = Type.GetType("NServiceBus.Pipeline.PipelineModifications, NServiceBus.Core");
var pipelineBuilderType = Type.GetType("NServiceBus.Pipeline.PipelineBuilder, NServiceBus.Core");
var pipelineModifications = typeof(ReadOnlySettings).GetMethods()
.Single(x => x.Name == "Get" && x.IsGenericMethod && x.GetParameters().Any() == false)
.MakeGenericMethod(pipelineModificationsType)
.Invoke(settings, null);
var pipelineBuilder = Activator.CreateInstance(pipelineBuilderType, pipelineModifications);
var incomingSteps = (List<RegisterStep>)pipelineBuilderType.GetProperty("Incoming").GetValue(pipelineBuilder);
var outgoingSteps = (List<RegisterStep>)pipelineBuilderType.GetProperty("Outgoing").GetValue(pipelineBuilder);
var sb = new StringBuilder();
sb.AppendLine("INCOMING");
sb.AppendLine("--------");
foreach (var step in incomingSteps)
{
sb.AppendLine(step.BehaviorType.Name);
}
Log.InfoFormat(sb.ToString());
sb.Clear();
sb.AppendLine("OUTGOING");
sb.AppendLine("--------");
foreach (var step in outgoingSteps)
{
sb.AppendLine(step.BehaviorType.Name);
}
Log.InfoFormat(sb.ToString());
}
public void Stop()
{
}
private static ILog Log = LogManager.GetLogger<PipelineInspector>();
}
@mikeminutillo
Copy link
Author

Drop this into an NSB v5 solution and it will log out the Incoming and Outgoing behavior pipelines.

NOTE: This relies on reflection as the API and the data is not exposed by the core. As such it is liable to stop working in any given version.

This will no longer work in v6 as the pipeline is more complex.

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