我有一个 Azure 函数,它在服务总线主题上触发,并将数据从 blob 存储复制到 Azure Cosmos Db Table Api。根据 Azure Blob 存储中的文件名,文件数据将作为实体复制到 Cosmos Db 表 Api 中的相应表中。
问题:我想在代码中为每个动态复制的文件引用表名,如果表不存在,我将在 cosmos db 中创建一个。
例如,我在 Azure 函数中有以下代码:
public static async void Run([ServiceBusTrigger("SBTopic", "SBSubscription", Connection = "AzureServiceBusString")] string mySbMsg,
[CosmosDB(
databaseName: "DBName",
collectionName: "{Dynamic table name}",
ConnectionStringSetting = "CosmosDBConnection")] DocumentClient client,
ILogger log)
{
try {
log.LogInformation($"C# ServiceBus topic trigger function processed message: {mySbMsg}");
// I get the variable name which will be my table name. Now refrencing this table name in Cosmos Db
CloudTable table = client.GetTableReference(client);
if (await table.CreateIfNotExistsAsync(Dynamic table name))
{ log("Created Table named: {0}", Dynamic table name);
// start copying entity
}
else
{ log("Table {0} already exists", Dynamic table name);
// start copying entity
}.
在此动态表名称中,将来自以相同方法运行的另一组代码。所以现在的问题是我如何首先处理我的 Cosmos Db 连接以及如何在代码中引用它。
谢谢