【发布时间】:2015-05-29 11:52:57
【问题描述】:
我需要在 IHandleMessages 接口的每个实例中测量 Handle 方法的调用时间。 我尝试使用温莎城堡拦截器,
public class NsbHandlerMeasurementInterceptor : IInterceptor
{
public void Intercept(IInvocation invocation)
{
if (invocation.Method.Name == ExpressionExtender.GetMethodName<IHandleMessages<DummyType>>(b => b.Handle(null)))
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
invocation.Proceed();
stopwatch.Stop();
// save stopwatch.ElapsedMilliseconds value
}
else
{
invocation.Proceed();
}
}
}
附安装代码:
container.Register(Component.For<NsbHandlerMeasurementInterceptor>());
container.Kernel.ComponentModelBuilder.AddContributor(new NsbWindsorModelConstructionContributor());
public class NsbWindsorModelConstructionContributor : IContributeComponentModelConstruction
{
public void ProcessModel(global::Castle.MicroKernel.IKernel kernel, global::Castle.Core.ComponentModel model)
{
if (model.Services.Any(s => s.ImplementsGenericInterface(typeof(IHandleMessages<>))))
{
model.Interceptors.AddIfNotInCollection(new InterceptorReference(typeof(NsbHandlerMeasurementInterceptor)));
}
}
}
但从那一刻起,Handle 方法没有触发。
我知道 NSB 中的性能计数器,但我需要更具体的、面向类型的测量。有可能实现吗?
【问题讨论】:
标签: c# castle-windsor nservicebus stopwatch nservicebus5