I am writing an azure webjob which reads events from eventhub using NET Core 3.1. I have a config file as below:
{
"JobHostConfig": {
"DashboardConnectionString": "",
"StorageConnectionString": "xx"
},
"EventHubConfig": {
"EventHubConnectionString": "xx",
"EventHubName": "xx",
"EventProcessorHostName": "xx",
"ConsumerGroupName": "xx",
"StorageConnectionString": "xx",
"StorageContainerName": "xx"
}
}
In the Main method, I call ConfigureServices method which looks something like:
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory() + $"\\..\\..\\..\\ConfigFiles")
.AddJsonFile($"applicationConfig.json", optional: true, reloadOnChange: true)
.AddJsonFile($"applicationConfig.{environment}.json", optional: true, reloadOnChange: true);
Configuration = builder.AddEnvironmentVariables()
.Build();
services.AddSingleton<IConfigurationRoot>(Configuration);
services.AddSingleton<IConfiguration>(Configuration);
services.AddMvcCore();
services.AddSingleton(GetInstance<EventHubConfig>());
services.AddSingleton(GetInstance<JobHostConfig>());
I confirmed that at runtime configs are getting populated in Configuration
only like this: Configuration["EventHubConfig:EventHubName"]
. But I also debugged that environment variables have not been set and its value is null
.
So when I do:
ProcessEvent([EventHubTrigger("%EventHubName%", ConsumerGroup = "%ConsumerGroupName%", Connection = "%ConnectionString%")] EventData eventData)
I get that %EventHubName%
is not resolved.
Also, when I hard-code the values of these then I get: No event hub receiver named.
Can someone suggest what is wrong with my registration?
Furthermore, I replaced the values with string in EventHubTrigger, and I get Value cannot be null. Parameter name: receiverConnectionString
When using %%
format, you should use Custom binding expressions.
For more details, please refer to this answer.
Please let me know if you still have more issues about it.