0

I've just updated a webjob to version 3 of the azure-sdk. The job has a TimerTrigger and as an alternative to create an appsettings.json file with the connectionstring I was hoping to use the TimerOptions class to set the ConnectionString but to my surprise the class is empty?!.

I stumbled across this https://github.com/Azure/azure-webjobs-sdk/issues/2178

Robert
  • 383
  • 1
  • 5
  • 20

1 Answers1

0

I found a workaround to the above scenario regarding the TimerTrigger. In the ConfigureHostConfiguration we can use the AddInMemoryCollection to set the connectionString "AzureWebJobsStorage".

Dictionary<string, string> connectionStrings =
   new Dictionary<string, string>
   {
      { "AzureWebJobsStorage", ConfigurationManager.ConnectionStrings["AzureWebJobsStorage"].ConnectionString},
};

builder.ConfigureHostConfiguration(config =>
   {
      config.AddInMemoryCollection(connectionStrings);
   });

Sadly this will not work on ServiceBusTriggers. But with ServiceBusTriggers we have an ServiceBusOptions that is not empty and can therefore be used.

builder.ConfigureWebJobs(b =>
   {
      b.AddAzureStorageCoreServices();
      b.AddServiceBus(options =>
      {
         options.MessageHandlerOptions.AutoComplete = false;
         options.ConnectionString = 
       ConfigurationManager.ConnectionStrings["AzureWebJobsServiceBus"].ConnectionString;
      });

      b.AddTimers();
});
Robert
  • 383
  • 1
  • 5
  • 20