The Retrieve operation retrieves the value for a given Object Store key. By default, the retrieved value becomes the message payload. To keep the current payload and store the retrieved value in a variable instead, use the target parameter (for example, target="myVar" so you can access the value as vars.myVar). See Set Up Watermarks with an Object Store for an example that uses target to avoid overriding the payload.
Use the Retrieve operation to read previously stored data in a flow, for example, to resume state, reuse cached values, or pass stored data to the next operation. For all parameters (including objectStore, target, and targetValue), see the Retrieve operation in the connector reference.
You can use the key to retrieve single values:
<os:retrieve key="userId" />
The operation returns the stored value (or the default value, if provided). When you don’t use the target parameter, that value becomes the new message payload for the rest of the flow.
You can use an operation like this one to provide default values when the key is not present in the store:
<os:retrieve key="timestamp">
<os:default-value>#[now()]</os:default-value>
</os:retrieve>
You can have default, complex structures:
<os:retrieve key="state">
<os:default-value>
<![CDATA[#[
output application/json
---
{
"id": attributes.queryParams.id,
"timestamp": now(),
"name": payload.name
}
]]]>
</os:default-value>
</os:retrieve>
Note that the defaultValue parameter handles cases in which no value exists for a given key. If you do not provide the parameter and the operation resolves to a null value, an OS:KEY_NOT_FOUND error is thrown. Otherwise, the defaultValue is returned but not stored.
|
|
All Object Store operations are synchronized at the key level. No other operation is able to access the same key on the same Object Store while the operation is running. If the runtime is running in cluster mode, this synchronization is also guaranteed across nodes.
|