Search code examples
c#azureazure-functionsazure-china

Azure Function with Eventhub Trigger fails with "Encountered error while fetching the list of EventHub PartitionIds -> Unauthorized"


There are a couple of stackoverflow posts which have similar issues but none of them have an authorization error problem.

I'm having problems running a Azure function with C# code with an eventhub trigger on Azure China. The same code runs fine on Azure global.

The connection string for the trigger is correct and I tried it with Listen and Manage rights, same problem.

Any help is appreciated.

Here the full error message:

Microsoft.Azure.WebJobs.Host.Listeners.FunctionListenerException: The listener for function 'FilterFunctionEventhubTrigger' was unable to start.

 ---> Microsoft.Azure.EventHubs.Processor.EventProcessorConfigurationException: Encountered error while fetching the list of EventHub PartitionIds

 ---> System.UnauthorizedAccessException: Unauthorized

   at Microsoft.Azure.EventHubs.Amqp.Management.AmqpServiceClient.GetRuntimeInformationAsync()

   at Microsoft.Azure.EventHubs.EventHubClient.GetRuntimeInformationAsync()

   at Microsoft.Azure.EventHubs.Processor.PartitionManager.GetPartitionIdsAsync()

   --- End of inner exception stack trace ---

   at Microsoft.Azure.EventHubs.Processor.PartitionManager.GetPartitionIdsAsync()

   at Microsoft.Azure.EventHubs.Processor.PartitionManager.GetPartitionIdsAsync()

   at Microsoft.Azure.EventHubs.Processor.PartitionManager.InitializeStoresAsync()

   at Microsoft.Azure.EventHubs.Processor.PartitionManager.StartAsync()

   at Microsoft.Azure.EventHubs.Processor.EventProcessorHost.RegisterEventProcessorFactoryAsync(IEventProcessorFactory factory, EventProcessorOptions processorOptions)

   at Microsoft.Azure.WebJobs.EventHubs.EventHubListener.StartAsync(CancellationToken cancellationToken)

   at Microsoft.Azure.WebJobs.Host.Listeners.FunctionListener.StartAsync(CancellationToken cancellationToken, Boolean allowRetry) in C:\projects\azure-webjobs-sdk-rqm4t\src\Microsoft.Azure.WebJobs.Host\Listeners\FunctionListener.cs:line 68

   --- End of inner exception stack trace --

Here my csproj file.

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <AzureFunctionsVersion>v3</AzureFunctionsVersion>
    <RootNamespace>sss_af_filter</RootNamespace>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Azure.Messaging.EventHubs" Version="5.6.0" />
    <PackageReference Include="Microsoft.ApplicationInsights.DependencyCollector" Version="2.18.0" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions" Version="4.0.1" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.EventHubs" Version="4.2.0" />
    <PackageReference Include="Microsoft.Azure.WebJobs.Logging.ApplicationInsights" Version="3.0.27" />
    <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.11" />
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
    <PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
    <PackageReference Include="System.Data.SqlClient" Version="4.8.2" />
    <PackageReference Include="xunit" Version="2.4.1" />
    <PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>
  </ItemGroup>
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
</Project>

Solution

  • The problem was a missing subnet in a VNet.