admin管理员组

文章数量:1401645

I'm trying to migrate my .NET 6 with Azure Functions v3 to .NET 9 and Functions v4 isolated mode.

I follow the Microsoft upgrade guideline, but I have some problem to migrate this code. I tried to do a lot of things, but it's still not working.

I this case is using Azure Service Bus - here's the code:

public static IHostBuilder ConfigureNServiceBus(this IHostBuilder hostBuilder)
{
    // Makes sure JObject is included in the NServiceBus scan
    JObject _ = new();

    var auditQueue = EnvironmentVariableHelper.GetConfigValue(IoC.Configuration, "AuditQueue", "audit");
    var errorQueue = EnvironmentVariableHelper.GetConfigValue(IoC.Configuration, "ErrorQueue", "error");
    var azureTableStorageConnectionString = EnvironmentVariableHelper.GetStringConfigValue("BlobStorageConnection");
    var endpointName = EnvironmentVariableHelper.GetStringConfigValue("ENDPOINT_NAME");
    var tableStorageName = endpointName.Replace("-", string.Empty).Replace(".", string.Empty);

    hostBuilder.UseNServiceBus(configuration =>
    {
        var endpointConfiguration = configuration.AdvancedConfiguration;                        
        endpointConfiguration.AuditProcessedMessagesTo(auditQueue);
        endpointConfiguration.SendFailedMessagesTo(errorQueue);
        endpointConfiguration.UseSerialization<NewtonsoftJsonSerializer>();

        var transport = configuration.Transport;
        transport.TopicName = $"{endpointName}.events";            
        transport.SubscriptionRuleNamingConvention = eventType => eventType.Name.Replace("App.Contracts", string.Empty);

        var conventions = endpointConfiguration.Conventions();
        conventions.DefiningCommandsAs(type => type.Namespace != null && type.Namespace.StartsWith("App.Contracts.Commands"));
        conventions.DefiningEventsAs(type => type.Namespace != null && type.Namespace.StartsWith("App.Contracts.Events"));
                    
        var persistence = endpointConfiguration.UsePersistence<AzureTablePersistence>();
        var tableServiceClient = new TableServiceClient(azureTableStorageConnectionString);
        persistence.UseTableServiceClient(tableServiceClient);
        persistence.DefaultTable(tableStorageName);
                    
        endpointConfiguration.AuditSagaStateChanges(serviceControlQueue: auditQueue);
                    
        ExcludeAssmbliesFromScan(endpointConfiguration);
                    
        endpointConfiguration.EnableInstallers();

        #if DEBUG
                   
        transport.MaxAutoLockRenewalDuration = TimeSpan.FromMinutes(30);
        #endif
    });

    return hostBuilder;
}

This is my ItemGroup:

<ItemGroup>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="2.0.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="2.0.1" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="2.0.1" />
    <PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.23.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="2.0.0" />

    <PackageReference Include="Google.Apis.Auth.AspNetCore3" Version="1.69.0" />
    <PackageReference Include="Mapster" Version="7.4.0" />
    <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="9.0.3" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.OpenApi" Version="1.5.1" />
    <PackageReference Include="Microsoft.Graph" Version="5.74.0" />
    
    <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.*" />
    <PackageReference Include="Microsoft.SqlServer.TransactSql.ScriptDom" Version="170.28.0" />
    <PackageReference Include="NServiceBus.Newtonsoft.Json" Version="4.1.0" />
    <PackageReference Include="NServiceBus.Extensions.Hosting" Version="2.0.0" />    
    <PackageReference Include="NServiceBus.AzureFunctions.Worker.ServiceBus" Version="6.0.0" />
    <PackageReference Include="NSwag.Generation.AspNetCore" Version="14.2.0" />
    <PackageReference Include="TinyMapper" Version="3.0.3" />
</ItemGroup>

The problem is on the this line

 var transport = configuration.Transport;
 transport.TopicName = $"{endpointName}.events";            
 transport.SubscriptionRuleNamingConvention = eventType => eventType.Name.Replace("App.Contracts", string.Empty);

I tried to do something like this

 var transport = new AzureServiceBusTransport(azureTableStorageConnectionString, TopicTopology.Default);
 transport.TopicName($"{endpointName}.events");
 transport.SubscriptionRuleNamingConvention = eventType => eventType.Name.Replace("App.Contracts", string.Empty);
 endpointConfiguration.UseTransport(transport);

but then I get this error:

'AzureServiceBusTransport' does not contain a definition for 'TopicName' and the best extension method overload 'AzureServiceBusTransportSettingsExtensions.TopicName(TransportExtensions, string)' requires a receiver of type 'NServiceBus.TransportExtensions<NServiceBus.AzureServiceBusTransport>'

'AzureServiceBusTransport.SubscriptionRuleNamingConvention' is obsolete: 'Setting the subscription rule name is accessible via the migration topology. Use MigrationTopology.EventToMigrate<TEventType>(string? ruleNameOverride = null) instead. The member currently throws a NotImplementedException. Will be removed in version 6.0.0.'

Can someone please help me?

Thanks

I'm trying to migrate my .NET 6 with Azure Functions v3 to .NET 9 and Functions v4 isolated mode.

I follow the Microsoft upgrade guideline, but I have some problem to migrate this code. I tried to do a lot of things, but it's still not working.

I this case is using Azure Service Bus - here's the code:

public static IHostBuilder ConfigureNServiceBus(this IHostBuilder hostBuilder)
{
    // Makes sure JObject is included in the NServiceBus scan
    JObject _ = new();

    var auditQueue = EnvironmentVariableHelper.GetConfigValue(IoC.Configuration, "AuditQueue", "audit");
    var errorQueue = EnvironmentVariableHelper.GetConfigValue(IoC.Configuration, "ErrorQueue", "error");
    var azureTableStorageConnectionString = EnvironmentVariableHelper.GetStringConfigValue("BlobStorageConnection");
    var endpointName = EnvironmentVariableHelper.GetStringConfigValue("ENDPOINT_NAME");
    var tableStorageName = endpointName.Replace("-", string.Empty).Replace(".", string.Empty);

    hostBuilder.UseNServiceBus(configuration =>
    {
        var endpointConfiguration = configuration.AdvancedConfiguration;                        
        endpointConfiguration.AuditProcessedMessagesTo(auditQueue);
        endpointConfiguration.SendFailedMessagesTo(errorQueue);
        endpointConfiguration.UseSerialization<NewtonsoftJsonSerializer>();

        var transport = configuration.Transport;
        transport.TopicName = $"{endpointName}.events";            
        transport.SubscriptionRuleNamingConvention = eventType => eventType.Name.Replace("App.Contracts", string.Empty);

        var conventions = endpointConfiguration.Conventions();
        conventions.DefiningCommandsAs(type => type.Namespace != null && type.Namespace.StartsWith("App.Contracts.Commands"));
        conventions.DefiningEventsAs(type => type.Namespace != null && type.Namespace.StartsWith("App.Contracts.Events"));
                    
        var persistence = endpointConfiguration.UsePersistence<AzureTablePersistence>();
        var tableServiceClient = new TableServiceClient(azureTableStorageConnectionString);
        persistence.UseTableServiceClient(tableServiceClient);
        persistence.DefaultTable(tableStorageName);
                    
        endpointConfiguration.AuditSagaStateChanges(serviceControlQueue: auditQueue);
                    
        ExcludeAssmbliesFromScan(endpointConfiguration);
                    
        endpointConfiguration.EnableInstallers();

        #if DEBUG
                   
        transport.MaxAutoLockRenewalDuration = TimeSpan.FromMinutes(30);
        #endif
    });

    return hostBuilder;
}

This is my ItemGroup:

<ItemGroup>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="2.0.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="2.0.1" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="2.0.1" />
    <PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.23.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="2.0.0" />

    <PackageReference Include="Google.Apis.Auth.AspNetCore3" Version="1.69.0" />
    <PackageReference Include="Mapster" Version="7.4.0" />
    <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="9.0.3" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.OpenApi" Version="1.5.1" />
    <PackageReference Include="Microsoft.Graph" Version="5.74.0" />
    
    <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.*" />
    <PackageReference Include="Microsoft.SqlServer.TransactSql.ScriptDom" Version="170.28.0" />
    <PackageReference Include="NServiceBus.Newtonsoft.Json" Version="4.1.0" />
    <PackageReference Include="NServiceBus.Extensions.Hosting" Version="2.0.0" />    
    <PackageReference Include="NServiceBus.AzureFunctions.Worker.ServiceBus" Version="6.0.0" />
    <PackageReference Include="NSwag.Generation.AspNetCore" Version="14.2.0" />
    <PackageReference Include="TinyMapper" Version="3.0.3" />
</ItemGroup>

The problem is on the this line

 var transport = configuration.Transport;
 transport.TopicName = $"{endpointName}.events";            
 transport.SubscriptionRuleNamingConvention = eventType => eventType.Name.Replace("App.Contracts", string.Empty);

I tried to do something like this

 var transport = new AzureServiceBusTransport(azureTableStorageConnectionString, TopicTopology.Default);
 transport.TopicName($"{endpointName}.events");
 transport.SubscriptionRuleNamingConvention = eventType => eventType.Name.Replace("App.Contracts", string.Empty);
 endpointConfiguration.UseTransport(transport);

but then I get this error:

'AzureServiceBusTransport' does not contain a definition for 'TopicName' and the best extension method overload 'AzureServiceBusTransportSettingsExtensions.TopicName(TransportExtensions, string)' requires a receiver of type 'NServiceBus.TransportExtensions<NServiceBus.AzureServiceBusTransport>'

'AzureServiceBusTransport.SubscriptionRuleNamingConvention' is obsolete: 'Setting the subscription rule name is accessible via the migration topology. Use MigrationTopology.EventToMigrate<TEventType>(string? ruleNameOverride = null) instead. The member currently throws a NotImplementedException. Will be removed in version 6.0.0.'

Can someone please help me?

Thanks

Share Improve this question edited Mar 23 at 17:49 marc_s 756k184 gold badges1.4k silver badges1.5k bronze badges asked Mar 23 at 16:07 Felipe Siqueira QueirozFelipe Siqueira Queiroz 233 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 3

NServiceBus.AzureFunctions.Worker.ServiceBus version 6 is designed to work with a new ASB transport topology, released in version 5 of the transport. Either see documentation to update configuration API code, or use version 5 of the hosting package.

本文标签: cIntegrating NServiceBus with Azure Functions V4 (isolated worker) in NET 9Stack Overflow