如何在Ruby的azure-storage-table gem中用连接串连接Azure Cosmos DB?
Azure Cosmos DB 与 azure-storage-table gem 连接问题解决方案
1. storage_account_name 参数的来源
你Cosmos DB连接串中AccountEndpoint里的{azureCosmosDBAccount}就是storage_account_name的取值,也就是你的Cosmos DB账户名称。例如如果你的AccountEndpoint是https://my-cosmos-account.documents.azure.com:443/,那么storage_account_name就是my-cosmos-account。
2. 直接使用完整连接串创建Client对象
可以直接通过完整连接串初始化Client,无需手动拆分参数。使用Azure::Storage::Table::TableService.from_connection_string方法即可实现,示例代码如下:
require 'azure/storage/table' # 替换为你的实际连接串 connection_string = "AccountEndpoint=https://{azureCosmosDBAccount}.documents.azure.com:443/;AccountKey={myAccountKey}" table_service = Azure::Storage::Table::TableService.from_connection_string(connection_string)
注意:确保你的Cosmos DB账户已启用Table API,且使用的azure-storage-table gem为支持该连接方式的新版本。
内容的提问来源于stack exchange,提问作者J. Naylor
相关产品推荐
相关产品推荐

