Azure Web作业多个连接字符串

minuzZ

Azure WebJob从Web应用程序(运行该作业)配置参数-AzureWebJobsStorage获取连接字符串。我需要使用一个WebJob监视不同存储中的两个队列。是否有可能以某种方式为WebJob提供多个连接字符串?

汤玛士

与这篇文章相关的是可能的:

对于您的情况,您想绑定到不同的存储帐户,以便您的功能看起来像这样:

public static void JobQueue1(
    [QueueTrigger("queueName1"),
    StorageAccount("storageAccount1ConnectionString")] string message)
{

}

public static void JobQueue2(
    [QueueTrigger("queueName2"),
    StorageAccount("storageAccount2ConnectionString")] string message)
{

}

如果要从config获取连接字符串,也可以实现自定义INameResolver:

public class ConfigNameResolver : INameResolver
{
    public string Resolve(string name)
    {
        string resolvedName = ConfigurationManager.AppSettings[name];
        if (string.IsNullOrWhiteSpace(resolvedName))
        {
            throw new InvalidOperationException("Cannot resolve " + name);
        }

        return resolvedName;
    }
}

使用它:

var config = new JobHostConfiguration();
config.NameResolver = new ConfigNameResolver();
...
new JobHost(config).RunAndBlock();

您的新函数如下所示:

public static void JobQueue1(
    [QueueTrigger("queueName1"),
    StorageAccount("%storageAccount2%")] string filename)
{

}

public static void JobQueue2(
    [QueueTrigger("queueName2"),
    StorageAccount("%storageAccount1%")] string filename)
{

}
  • storageAccount1和storageAccount2是 appSettings

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Azure Web 应用和 Web 作业的不同连接字符串

如何获取 Web 作业以使用 azure 门户存储连接字符串,而不是 Web 作业控制台应用程序部署的配置文件中的内容?

在Azure Web App中设置EF连接字符串

Azure按需Web作业未收到格式正确的json序列化字符串

Azure移动EasyTables连接字符串

Azure错误-连接字符串困难

在Azure中为ASP.NET Core Web应用设置SQL连接字符串

Azure Web应用程序找不到连接字符串

具有Azure功能和Web API的EF Core连接字符串设置

在Azure中的Web应用之间共享连接字符串

多个单元是否意味着Azure IoT中心和事件中心中有多个连接字符串?

从Azure网站连接字符串配置中读取连接字符串

大型JSON字符串的SQL Azure连接已关闭

从Uri和连接字符串创建Azure BlobClient

使用连接字符串对 Azure 进行身份验证

Azure WebJobs连接字符串配置(AzureWebJobsDashboard ??)

如何为 Azure 重新生成连接字符串?

SQL Azure 连接字符串中的密码转义

将 Azure 连接字符串与 Django WebApp 链接?

Azure函数中实体框架的连接字符串

如何从Azure KeyVault中获取连接字符串?

Umbraco、Azure 部署槽和连接字符串

在Azure App Service设置中存储连接字符串

Azure Functions数据库连接字符串

无法删除所有Azure网站连接字符串

Azure App从machine.config获取连接字符串

Azure.Messaging.ServiceBus.ServiceBusClient 的连接字符串

无法解析Azure Cloud Storage中的连接字符串

Azure 函数连接字符串部署问题