-
-
Save SzymonPobiega/8d63f1372a9d366ec0e7d8ee7a6ec4f7 to your computer and use it in GitHub Desktop.
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
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