Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var routerConfiguation = new RouterConfiguration("Router");
routerConfiguation.AddInterface<MsmqTransport>("MSMQ", t => {}).DisableMessageDrivenPublishSubscribe();
routerConfiguation.AddInterface<SqlServerTransport>("SQL", t => t.ConnectionString(myConnectionString)).DisableMessageDrivenPublishSubscribe();
routerConfiguation.Chains.AddRule(c => new MetricsPreroutingTerminator("MSMQ", "Particular.Monitoring@some-machine"));
routerConfiguation.UseStaticRoutingProtocol();
var router = Router.Create(routerConfiguation);
await router.Start().ConfigureAwait(false);
class MetricsPreroutingTerminator : ChainTerminator<PreroutingContext>
{
string metricsEndpoint;
string metricsInterface;
public MetricsPreroutingTerminator(string metricsInterface, string metricsEndpoint)
{
this.metricsEndpoint = metricsEndpoint;
this.metricsInterface = metricsInterface;
}
protected override async Task<bool> Terminate(PreroutingContext context)
{
if (context.Headers.TryGetValue(Headers.EnclosedMessageTypes, out var messageTypes)
&& messageTypes == "NServiceBus.Metrics.EndpointMetadataReport")
{
var interfaces = context.Extensions.Get<IInterfaceChains>();
await interfaces.GetChainsFor(metricsInterface).Get<AnycastContext>()
.Invoke(new AnycastContext(metricsEndpoint, new OutgoingMessage(context.MessageId, context.Headers.Copy(), context.Body), DistributionStrategyScope.Send, context))
.ConfigureAwait(false);
return true;
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment