Exemplo n.º 1
0
        public IDocumentClient GetClient(CosmosDbSetting setting)
        {
            var dbConn = GetDbConnection(setting);
            var client = new DocumentClient(dbConn.VaultUrl, dbConn.AuthorizationKey, JsonSerializerSettings, dbConn.ConnectionPolicy);

            return(client);
        }
Exemplo n.º 2
0
        public async Task <IBulkExecutor> GetBulkExecutor(CosmosDbSetting setting)
        {
            var dbConn = GetDbConnection(setting);

            dbConn.ConnectionPolicy.RetryOptions.MaxRetryWaitTimeInSeconds           = 30;
            dbConn.ConnectionPolicy.RetryOptions.MaxRetryAttemptsOnThrottledRequests = 9;

            var client     = new DocumentClient(dbConn.VaultUrl, dbConn.AuthorizationKey, JsonSerializerSettings, dbConn.ConnectionPolicy);
            var collection = await client.EnsureDatabaseAndCollection(setting.DbName, setting.CollectionName);

            return(await CreateBulkExecutor(client, collection));
        }
Exemplo n.º 3
0
        private (Uri VaultUrl, string AuthorizationKey, ConnectionPolicy ConnectionPolicy) GetDbConnection(CosmosDbSetting setting)
        {
            var endpointUrl      = $"https://{setting.AccountName}.documents.azure.com:443/";
            var connectionPolicy = new ConnectionPolicy()
            {
                ConnectionMode     = ConnectionMode.Direct,
                ConnectionProtocol = Protocol.Tcp,
                RequestTimeout     = TimeSpan.FromSeconds(setting.TimeoutInSeconds)
            };

            return(new Uri(endpointUrl), setting.AuthKey, connectionPolicy);
        }