【问题标题】:How to programmatically set connection string for AzureStorage, EventHub in webjob如何在 webjob 中以编程方式为 AzureStorage、EventHub 设置连接字符串
【发布时间】:2022-08-19 06:50:34
【问题描述】:

正如标题所说,我们如何在配置设置期间以编程方式设置连接字符串,如下所示

builder.ConfigureWebJobs(b =>
{
    b.AddAzureStorageCoreServices();
    b.AddEventHubs(config =>
    {
        config.MaxEventBatchSize = 10;
    });
    b.AddAzureStorageQueues(config =>
    {
        config.BatchSize = 8;
    });
});

目前它被配置为从应用程序设置中读取,如下所示,但我正在寻找一种在上述配置设置期间设置它的方法。

public static void ProcessEventHubMessage([EventHubTrigger(\"%hubname%\", Connection = \"EventHubConnection\")] EventData[] message, TextWriter log)
 
public static void ProcessQueueMessage([QueueTrigger(\"%queuename%\", Connection = \"AzureWebJobsStorage\")] string message, TextWriter log)

    标签: azure azure-storage azure-webjobs azure-eventhub azure-queues


    【解决方案1】:

    你的问题对我来说真的没有意义,但我还是试着回答一下。通常,您在 appsettings.json 中为您的服务设置连接字符串。如果您想以编程方式更改它们,只需在实例化服务时更改它们。

    processor = new EventProcessorClient(storageClient, consumerGroup, eventHubConnectionString, eventHubName);
    

    只需将“eventHubConnectionString”更改为您想要的任何内容。存储也是如此。

    【讨论】:

      猜你喜欢
      • 2010-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-01
      • 2011-05-31
      • 2011-05-02
      • 1970-01-01
      • 2014-12-03
      相关资源
      最近更新 更多