|
1 |
| -use anyhow::Result; |
2 |
| -use azure_data_cosmos::prelude::Operation; |
| 1 | +use anyhow::{Context, Result}; |
3 | 2 | use azure_data_cosmos::{
|
4 |
| - prelude::{AuthorizationToken, CollectionClient, CosmosClient, Query}, |
| 3 | + prelude::{ |
| 4 | + AuthorizationToken, CollectionClient, CosmosClient, CosmosClientBuilder, Operation, Query, |
| 5 | + }, |
5 | 6 | CosmosEntity,
|
6 | 7 | };
|
7 | 8 | use futures::StreamExt;
|
@@ -88,14 +89,28 @@ impl KeyValueAzureCosmos {
|
88 | 89 | )
|
89 | 90 | }
|
90 | 91 | };
|
91 |
| - let cosmos_client = CosmosClient::new(account, token); |
| 92 | + let cosmos_client = cosmos_client(account, token)?; |
92 | 93 | let database_client = cosmos_client.database_client(database);
|
93 | 94 | let client = database_client.collection_client(container);
|
94 | 95 |
|
95 | 96 | Ok(Self { client, app_id })
|
96 | 97 | }
|
97 | 98 | }
|
98 | 99 |
|
| 100 | +fn cosmos_client(account: impl Into<String>, token: AuthorizationToken) -> Result<CosmosClient> { |
| 101 | + if cfg!(feature = "connection-pooling") { |
| 102 | + let client = reqwest::ClientBuilder::new() |
| 103 | + .build() |
| 104 | + .context("failed to build reqwest client")?; |
| 105 | + let transport_options = azure_core::TransportOptions::new(std::sync::Arc::new(client)); |
| 106 | + Ok(CosmosClientBuilder::new(account, token) |
| 107 | + .transport(transport_options) |
| 108 | + .build()) |
| 109 | + } else { |
| 110 | + Ok(CosmosClient::new(account, token)) |
| 111 | + } |
| 112 | +} |
| 113 | + |
99 | 114 | #[async_trait]
|
100 | 115 | impl StoreManager for KeyValueAzureCosmos {
|
101 | 116 | async fn get(&self, name: &str) -> Result<Arc<dyn Store>, Error> {
|
|
0 commit comments