NServiceBus:访问功能中的可恢复性

NServiceBus: Access to recoverability in feature

使用 NServiceBus v7.4.6 加上 .NET Core 3.1 并获取异常

字典中不存在给定键 NServiceBus.RecoverabilitySettings。

尝试在功能中获取 RecoverabilitySettings 时使用以下代码。有什么问题吗?

public class MyFeature : Feature
{
    protected override void Setup(FeatureConfigurationContext context)
    {
        var recoverability = context.Settings.Get<RecoverabilitySettings>();
        recoverability.Failed(settings => settings.OnMessageSentToErrorQueue(message =>
        {
            Console.WriteLine(message.MessageId);
            return Task.CompletedTask;
        }));
    }
}

public static class Program
{
    public static async Task Main()
    {
        var configuration = new ConfigurationBuilder()
            .AddJsonFile("appsettings.json")
            .Build();

        var host = Host
            .CreateDefaultBuilder()
            .UseConsoleLifetime()
            .UseNServiceBus(c =>
            {
                var endpointConfiguration = new EndpointConfiguration("MyEndpoint");
                
                var connectionString = configuration.GetConnectionString("AzureServiceBusTransport");
                var transport = endpointConfiguration.UseTransport<AzureServiceBusTransport>();
                transport.ConnectionString(connectionString);
                endpointConfiguration.EnableFeature<MyFeature>();
                
                return endpointConfiguration;
            })
            .Build();

        await host.RunAsync();
    }
}

更新

我尝试 update the feature 从 NServiceBus 的旧版本 7 到 ErrorsNotifications.MessageSentToErrorQueue 已过时的最新版本。旧的功能代码就像

public class MyOldFeature : Feature
{
    protected override void Setup(FeatureConfigurationContext context)
    {
        var notifications = context.Settings.Get<Notifications>();
        notifications.Errors.MessageSentToErrorQueue += this.OnMessageSentToErrorQueue;
    }

    private void OnMessageSentToErrorQueue(object sender, FailedMessage message)
    {
        Console.WriteLine(message.MessageId);
    }
}

来源:https://docs.particular.net/nservicebus/upgrades/7to8/#error-notification-events

In NServiceBus version 7.2, error notification events for MessageSentToErrorQueue, MessageHasFailedAnImmediateRetryAttempt, and MessageHasBeenSentToDelayedRetries using .NET events were deprecated in favor of Task-based callbacks. In NServiceBus version 8 and above, the event-based notifications will throw an error.

Error notifications can be set with the Task-based callbacks through the recoverability settings:

设置 API 不是类型安全的,行为可能会在主要版本之间发生变化,这会阻止在这种情况下 RecoverabilitySettings 使用过时,因为该类型仍在使用。

我创建了以下问题,因为我认为我们可以在有关此特定重大更改的反馈中做得更好:

https://github.com/Particular/NServiceBus/issues/6080