I have azure functions that is triggered by service bus queue. Everything is working fine in local. I have added the ServiceBusConnectionString in azure portal's configuration But still Environment.GetEnvironmentVariable("ServiceBusConnectionString") is returning null. There are few similar problems available in stackoverflow. But None of these solution works.
public class ServiceBusPolar
{
private readonly IEmailService _emailRepo;
private readonly string BASEURL;
private static HttpClient httpClient;
public static string QUEUE_NAME;
public static string ServiceBusConnectionString;
public ServiceBusPolar(IEmailService emailRepo)
{
_emailRepo = emailRepo;
BASEURL = Environment.GetEnvironmentVariable("BaseURL");
httpClient = new HttpClient();
QUEUE_NAME = Environment.GetEnvironmentVariable("MessageQueueName");
ServiceBusConnectionString = Environment.GetEnvironmentVariable("ServiceBusConnectionString");
//Utl = new Utility();
}
[FunctionName("ServiceBusPolar")]
public async Task Run([ServiceBusTrigger("emailqueue", Connection = "ServiceBusConnectionString")] Message message, ILogger log)
{
log.LogInformation($"MessageQueueName is {QUEUE_NAME} and Service bus connection string is {ServiceBusConnectionString} and directly {Environment.GetEnvironmentVariable("ServiceBusConnectionString")}");
string payload = Encoding.UTF8.GetString(message.Body);
//More logic below is removed to make the code short
}
}
}
In above code, I have logged the QueueName and ServiceBusConnectionString. But when this function runs in production, These fields are coming empty.
We can clearly see in this above picture that fields are coming null.
Screenshot of my configuration inside azure portal.