-
Notifications
You must be signed in to change notification settings - Fork 46
New CosmosDbBackoffPolicy
Create a new Backoff Policy that can be added to a Cosmos DB Context to control the behavior when "Too Many Request" (error code 429) responses are recieved.
New-CosmosDbBackoffPolicy [[-MaxRetries] <Int32>] [[-Method] <String>] [[-Delay] <Int32>] [<CommonParameters>]
This function creates a new Back-off Policy that can be used to control the behavior of most Cosmos DB functions when a "Too Many Request" (error code 429) response is recieved.
If a Back-off Policy is applied to a context that is used with a Cosmos DB function and an error code 429 is recieved then a Back-off Policy can be used to control whether or not to retry the request.
If no Back-off Policy is defined then the 429 error is simply returned to the caller.
The default back-off method will use the largest of the two values,
delay and x-ms-retry-after-ms
each time.
An additive back-off method will add the delay to the value of the
x-ms-retry-after-ms
header each time.
A linear back-off method will use a delay equal to the delay times the number of retries.
An exponential back-off method will exponentially increase the delay with value each retry.
A random back-off method will wait +/- 50% of the delay value each retry.
Note: If a calculated delay results in a value less than the
x-ms-retry-after-ms
header value then the x-ms-retry-after-ms
value will be used.
PS C:\> $primaryKey = ConvertTo-SecureString -String 'your master key' -AsPlainText -Force
PS C:\> $backoffPolicy = New-CosmosDBBackoffPolicy -MaxRetries 5
PS C:\> $cosmosDbContext = New-CosmosDbContext -Account 'MyAzureCosmosDB' -Database 'MyDatabase' -Key $primaryKey -BackoffPolicy $backoffPolicy
PS C:\> $query = "SELECT * FROM customers c WHERE (c.id = '[email protected]')"
PS C:\> $documents = Get-CosmosDBDocument -Context $cosmosDBContext -CollectionId 'MyNewCollection' -Query $query
Creates a CosmosDB context specifying the master key manually. A
Back-off Policy will be applied to the context that allows 5 retries
with a delay between them matching the x-ms-retry-after-ms
header
value returned from Cosmos DB.
PS C:\> $primaryKey = ConvertTo-SecureString -String 'your master key' -AsPlainText -Force
PS C:\> $backoffPolicy = New-CosmosDBBackoffPolicy -MaxRetries 5 -Delay 2000
PS C:\> $cosmosDbContext = New-CosmosDbContext -Account 'MyAzureCosmosDB' -Database 'MyDatabase' -Key $primaryKey -BackoffPolicy $backoffPolicy
PS C:\> $query = "SELECT * FROM customers c WHERE (c.id = '[email protected]')"
PS C:\> $documents = Get-CosmosDBDocument -Context $cosmosDBContext -CollectionId 'MyNewCollection' -Query $query
Creates a CosmosDB context specifying the master key manually. A Back-off Policy will be applied to the context that allows 5 retries with a delay of 2 seconds between them.
PS C:\> $primaryKey = ConvertTo-SecureString -String 'your master key' -AsPlainText -Force
PS C:\> $backoffPolicy = New-CosmosDBBackoffPolicy -MaxRetries 10 -Method Default -Delay 100
PS C:\> $cosmosDbContext = New-CosmosDbContext -Account 'MyAzureCosmosDB' -Database 'MyDatabase' -Key $primaryKey -BackoffPolicy $backoffPolicy
PS C:\> $query = "SELECT * FROM customers c WHERE (c.id = '[email protected]')"
PS C:\> $documents = Get-CosmosDBDocument -Context $cosmosDBContext -CollectionId 'MyNewCollection' -Query $query
Creates a CosmosDB context specifying the master key manually. A
Back-off Policy will be applied to the context that allows 10 retries.
A delay of 100ms will always be used unless it is less than the
x-ms-retry-after-ms
header.
PS C:\> $primaryKey = ConvertTo-SecureString -String 'your master key' -AsPlainText -Force
PS C:\> $backoffPolicy = New-CosmosDbBackoffPolicy -MaxRetries 10 -Method Additive -Delay 1000
PS C:\> $cosmosDbContext = New-CosmosDbContext -Account 'MyAzureCosmosDB' -Database 'MyDatabase' -Key $primaryKey -BackoffPolicy $backoffPolicy
PS C:\> $query = "SELECT * FROM customers c WHERE (c.id = '[email protected]')"
PS C:\> $documents = Get-CosmosDBDocument -Context $cosmosDBContext -CollectionId 'MyNewCollection' -Query $query
Creates a CosmosDB context specifying the master key manually. A
Back-off Policy will be applied to the context that allows 10 retries.
The delay between each retry will be the returned x-ms-retry-after-ms
header value plus 1000ms.
PS C:\> $primaryKey = ConvertTo-SecureString -String 'your master key' -AsPlainText -Force
PS C:\> $backoffPolicy = New-CosmosDbBackoffPolicy -MaxRetries 3 -Method Linear -Delay 500
PS C:\> $cosmosDbContext = New-CosmosDbContext -Account 'MyAzureCosmosDB' -Database 'MyDatabase' -Key $primaryKey -BackoffPolicy $backoffPolicy
PS C:\> $query = "SELECT * FROM customers c WHERE (c.id = '[email protected]')"
PS C:\> $documents = Get-CosmosDBDocument -Context $cosmosDBContext -CollectionId 'MyNewCollection' -Query $query
Creates a CosmosDB context specifying the master key manually. A Back-off Policy will be applied to the context that allows 3 retries. The delay between each retry will wait for 500ms on the first retry, 1000ms on the second retry, 1500ms on final retry.
PS C:\> $primaryKey = ConvertTo-SecureString -String 'your master key' -AsPlainText -Force
PS C:\> $backoffPolicy = New-CosmosDbBackoffPolicy -MaxRetries 4 -Method Exponential -Delay 1000
PS C:\> $cosmosDbContext = New-CosmosDbContext -Account 'MyAzureCosmosDB' -Database 'MyDatabase' -Key $primaryKey -BackoffPolicy $backoffPolicy
PS C:\> $query = "SELECT * FROM customers c WHERE (c.id = '[email protected]')"
PS C:\> $documents = Get-CosmosDBDocument -Context $cosmosDBContext -CollectionId 'MyNewCollection' -Query $query
Creates a CosmosDB context specifying the master key manually. A Back-off Policy will be applied to the context that allows 3 retries. The delay between each retry will wait for 1000ms on the first retry, 4000ms on the second retry, 9000ms on the 3rd retry and 16000ms on the final retry.
PS C:\> $primaryKey = ConvertTo-SecureString -String 'your master key' -AsPlainText -Force
PS C:\> $backoffPolicy = New-CosmosDbBackoffPolicy -MaxRetries 3 -Method Random -Delay 1000
PS C:\> $cosmosDbContext = New-CosmosDbContext -Account 'MyAzureCosmosDB' -Database 'MyDatabase' -Key $primaryKey -BackoffPolicy $backoffPolicy
PS C:\> $query = "SELECT * FROM customers c WHERE (c.id = '[email protected]')"
PS C:\> $documents = Get-CosmosDBDocument -Context $cosmosDBContext -CollectionId 'MyNewCollection' -Query $query
Creates a CosmosDB context specifying the master key manually. A Back-off Policy will be applied to the context that allows 3 retries. The delay adds or subtracts up to 50% of the delay period to the base delay each time can also be applied. For example, the first delay might be 850ms, with the second delay being 1424ms and final delay being 983ms.
This is the number of milliseconds to wait before retrying the last request. The behavior of this value depends on the method. See the description of this function for more detail.
Type: Int32
Parameter Sets: (All)
Aliases:
Required: False
Position: 2
Default value: 5000
Accept pipeline input: False
Accept wildcard characters: False
This is the number of times to retry the request if a 429 error is recieved.
Type: Int32
Parameter Sets: (All)
Aliases:
Required: False
Position: 0
Default value: 10
Accept pipeline input: False
Accept wildcard characters: False
This is the back-off method of the policy.
Type: String
Parameter Sets: (All)
Aliases:
Accepted values: Default, Additive, Linear, Exponential, Random
Required: False
Position: 1
Default value: Default
Accept pipeline input: False
Accept wildcard characters: False
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
- ConvertTo-CosmosDbTokenDateString
- Get-CosmosDbAccount
- Get-CosmosDbAccountConnectionString
- Get-CosmosDbAccountMasterKey
- Get-CosmosDbAttachment
- Get-CosmosDbAttachmentResourcePath
- Get-CosmosDbAuthorizationHeaderFromContext
- Get-CosmosDbCollection
- Get-CosmosDbCollectionResourcePath
- Get-CosmosDbDatabase
- Get-CosmosDbDatabaseResourcePath
- Get-CosmosDbDocument
- Get-CosmosDbDocumentResourcePath
- Get-CosmosDbEntraIdToken
- Get-CosmosDbOffer
- Get-CosmosDbOfferResourcePath
- Get-CosmosDbPermission
- Get-CosmosDbPermissionResourcePath
- Get-CosmosDbStoredProcedure
- Get-CosmosDbStoredProcedureResourcePath
- Get-CosmosDbTrigger
- Get-CosmosDbTriggerResourcePath
- Get-CosmosDbUri
- Get-CosmosDbUser
- Get-CosmosDbUserDefinedFunction
- Get-CosmosDbUserDefinedFunctionResourcePath
- Get-CosmosDbUserResourcePath
- Invoke-CosmosDbRequest
- Invoke-CosmosDbStoredProcedure
- New-CosmosDbAccount
- New-CosmosDbAccountMasterKey
- New-CosmosDbAttachment
- New-CosmosDbBackoffPolicy
- New-CosmosDbContext
- New-CosmosDbCollection
- New-CosmosDbCollectionExcludedPath
- New-CosmosDbCollectionIncludedPath
- New-CosmosDbCollectionIncludedPathIndex
- New-CosmosDbCollectionIndexingPolicy
- New-CosmosDbCollectionUniqueKey
- New-CosmosDbCollectionUniqueKeyPolicy
- New-CosmosDbDatabase
- New-CosmosDbDocument
- New-CosmosDbInvalidArgumentException
- New-CosmosDbInvalidOperationException
- New-CosmosDbPermission
- New-CosmosDbStoredProcedure
- New-CosmosDbTrigger
- New-CosmosDbUser
- New-CosmosDbUserDefinedFunction
- Remove-CosmosDbAccount
- Remove-CosmosDbAttachment
- Remove-CosmosDbCollection
- Remove-CosmosDbDatabase
- Remove-CosmosDbDocument
- Remove-CosmosDbPermission
- Remove-CosmosDbStoredProcedure
- Remove-CosmosDbTrigger
- Remove-CosmosDbUser
- Remove-CosmosDbUserDefinedFunction
- Set-CosmosDbAccount
- Set-CosmosDbAttachment
- Set-CosmosDbAttachmentType
- Set-CosmosDbCollectionType
- Set-CosmosDbDatabaseType
- Set-CosmosDbDocument
- Set-CosmosDbDocumentType
- Set-CosmosDbOffer
- Set-CosmosDbOfferType
- Set-CosmosDbPermissionType
- Set-CosmosDbStoredProcedure
- Set-CosmosDbStoredProcedureType
- Set-CosmosDbTrigger
- Set-CosmosDbTriggerType
- Set-CosmosDbUser
- Set-CosmosDbUserDefinedFunction
- Set-CosmosDbUserDefinedFunctionType
- Set-CosmosDbUserType