azure_cosmosdb
Creates or updates messages as JSON documents in Azure CosmosDB.
Introduced in version v4.25.0.
When creating documents, each message must have the id
property (case-sensitive) set (or use auto_id: true
). It is the unique name that identifies the document, that is, no two documents share the same id
within a logical partition. The id
field must not exceed 255 characters. See details.
The partition_keys
field must resolve to the same value(s) across the entire message batch.
Credentials
You can use one of the following authentication mechanisms:
- Set the
endpoint
field and theaccount_key
field - Set only the
endpoint
field to use DefaultAzureCredential - Set the
connection_string
field
Batching
CosmosDB limits the maximum batch size to 100 messages and the payload must not exceed 2MB (details here).
Performance
This output benefits from sending multiple messages in flight in parallel for improved performance. You can tune the max number of in flight messages (or message batches) with the field max_in_flight
.
This output benefits from sending messages as a batch for improved performance. Batches can be formed at both the input and output level. You can find out more in this doc.
Examples
Create new documents in the blobfish
container with partition key /habitat
.
Execute the Patch operation on documents from the blobfish
container.
Fields
endpoint
CosmosDB endpoint.
Type: string
account_key
Account key.
Type: string
connection_string
Connection string.
Type: string
database
Database.
Type: string
container
Container.
Type: string
partition_keys_map
A Bloblang mapping which should evaluate to a single partition key value or an array of partition key values of type string, integer or boolean. Currently, hierarchical partition keys are not supported so only one value may be provided.
Type: string
operation
Operation.
Type: string
Default: "Create"
Option | Summary |
---|---|
Create | Create operation. |
Delete | Delete operation. |
Patch | Patch operation. |
Replace | Replace operation. |
Upsert | Upsert operation. |
patch_operations
Patch operations to be performed when operation: Patch
.
Type: array
patch_operations[].operation
Operation.
Type: string
Default: "Add"
Option | Summary |
---|---|
Add | Add patch operation. |
Increment | Increment patch operation. |
Remove | Remove patch operation. |
Replace | Replace patch operation. |
Set | Set patch operation. |
patch_operations[].path
Path.
Type: string
patch_operations[].value_map
A Bloblang mapping which should evaluate to a value of any type that is supported by CosmosDB.
Type: string
patch_condition
Patch operation condition. This field supports interpolation functions.
Type: string
auto_id
Automatically set the item id
field to a random UUID v4. If the id
field is already set, then it will not be overwritten. Setting this to false
can improve performance, since the messages will not have to be parsed.
Type: bool
Default: true
item_id
ID of item to replace or delete. Only used by the Replace and Delete operations This field supports interpolation functions.
Type: string
batching
Allows you to configure a batching policy.
Type: object
batching.count
A number of messages at which the batch should be flushed. If 0
disables count based batching.
Type: int
Default: 0
batching.byte_size
An amount of bytes at which the batch should be flushed. If 0
disables size based batching.
Type: int
Default: 0
batching.period
A period in which an incomplete batch should be flushed regardless of its size.
Type: string
Default: ""
batching.check
A Bloblang query that should return a boolean value indicating whether a message should end a batch.
Type: string
Default: ""
batching.processors
A list of processors to apply to a batch as it is flushed. This allows you to aggregate and archive the batch however you see fit. Please note that all resulting messages are flushed as a single batch, therefore splitting the batch into smaller batches using these processors is a no-op.
Type: array
max_in_flight
The maximum number of messages to have in flight at a given time. Increase this to improve throughput.
Type: int
Default: 64
CosmosDB emulator
If you wish to run the CosmosDB emulator that is referenced in the documentation here, the following Docker command should do the trick:
Note: AZURE_COSMOS_EMULATOR_PARTITION_COUNT
controls the number of partitions that will be supported by the emulator. The bigger the value, the longer it takes for the container to start up.
Additionally, instead of installing the container self-signed certificate which is exposed via [mitmproxy](https://localhost:8081/_explorer/emulator.pem
, you can run https://mitmproxy.org/) like so:
Then you can access the CosmosDB UI via http://localhost:8080/_explorer/index.html
and use http://localhost:8080
as the CosmosDB endpoint.