This is part of the NServiceBus Upgrade Guide from Version 6 to 7, which also includes the following individual upgrade guides for specific components:
Transports
- Migrating MSMQ subscription messages
- Azure Service Bus Transport (Legacy) Upgrade Version 7 to 8
- Azure Storage Queues Transport Upgrade Version 7 to 8
- RabbitMQ Transport Upgrade Version 4 to 5
- SQL Server Transport Upgrade Version 3 to 4
Persistence
Hosting
Other
RegisterObservers replaces basic methods
The EnableMetricTracing
, EnableCustomReport
and EnableLogTracing
methods have been deprecated and replaced with the more extensible RegisterObservers
.
Also note that the older methods supported an interval
TimeSpan. It is now the responsibility of the implementing code to batch metrics and flush them as needed.
Changes in RegisterObservers
The RegisterObservers API has changed to take ref
events.
// For Metrics version 2.x
var metrics = endpointConfiguration.EnableMetrics();
metrics.RegisterObservers(
register: context =>
{
foreach (var duration in context.Durations)
{
duration.Register(
observer: (ref DurationEvent @event) =>
{
log.Info($"Duration: '{duration.Name}'. Value: '{@event.Duration}'");
});
}
foreach (var signal in context.Signals)
{
signal.Register(
observer: (ref SignalEvent @event) =>
{
log.Info($"Signal: '{signal.Name}'. Type: '{@event.MessageType}'");
});
}
});
// For Metrics version 1.x
var metrics = endpointConfiguration.EnableMetrics();
metrics.RegisterObservers(
register: context =>
{
foreach (var duration in context.Durations)
{
duration.Register(
observer: length =>
{
log.Info($"Duration: '{duration.Name}'. Value: '{length}'");
});
}
foreach (var signal in context.Signals)
{
signal.Register(
observer: () =>
{
log.Info($"signal: '{signal.Name}'");
});
}
});