0

I am using Azure webjobs version 3.x for EventHub trigger. Provided the event hub connection string in the appSettings.json file by using the field "EventHubConnection". But when i tried to run the function, i am getting below error: Microsoft.Azure.WebJobs.Host.Indexers.FunctionIndexingException: 'Error indexing method 'Functions.Trigger'' InvalidOperationException: No event hub receiver named

Program.cs

var builder = new HostBuilder();
builder.ConfigureWebJobs(b =>
{
    b.AddEventHubs();
});
var host = builder.Build();
using (host)
{
     host.Run();
}

Function.cs:

public static void Trigger([EventHubTrigger("my eventhub name")] EventData message, ILogger logger)
{
    string data = Encoding.UTF8.GetString(message.Body);
    logger.LogDebug(".....");
}

appsettings.json:

{
  "ConnectionStrings": {
    "EventHubConnection": "Endpoint=....."
  }
}
Ivan Glasenberg
  • 29,865
  • 2
  • 44
  • 60
sindhuja
  • 87
  • 7

1 Answers1

1

Please use the following code and settings:

appsettings.json(also remember right click the appsettings.json file -> click propertities -> set the "Copy to output directory" to "copy if newer"):

{  
  "AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=xxx;AccountKey=xxx;EndpointSuffix=core.windows.net", 
  "EventHubConnectionString": "Endpoint=sb://xxxx"
}

Function.cs:

public static void Trigger([EventHubTrigger("my eventhub name",Connection = "EventHubConnectionString")] EventData message, ILogger logger)
{

    string data = Encoding.UTF8.GetString(message.Body);
    Console.WriteLine(data+";;xxx");
}

Test result:

enter image description here

Ivan Glasenberg
  • 29,865
  • 2
  • 44
  • 60