DBOS Methods & Variables
Workflow Communication Methods
getEvent
<T> Optional<T> getEvent(String workflowId, String key, Duration timeout)
Retrieve the latest value of an event published by the workflow identified by workflowId to the key key.
If the event does not yet exist, wait for it to be published, returning empty if the wait times out. If the calling workflow is cancelled while waiting, throws DBOSWorkflowCancelledException.
Parameters:
- workflowId: The identifier of the workflow whose events to retrieve.
- key: The key of the event to retrieve.
- timeout: A timeout duration. If the wait times out, an empty Optional is returned.
setEvent
void setEvent(String key, Object value)
void setEvent(String key, Object value, SerializationStrategy serialization)
Create and associate with this workflow an event with key key and value value.
If the event already exists, update its value.
setEvent can only be called from within a workflow.
Parameters:
- key: The key of the event.
- value: The value of the event. Must be serializable.
- serialization: The serialization strategy to use for this event. Defaults to
SerializationStrategy.DEFAULT, which uses the serialization format recorded for the calling workflow.
getAllEvents
Map<String, Object> getAllEvents(String workflowId)
Retrieve all events published by the workflow identified by workflowId, returned as a map of event key to deserialized value.
Parameters:
- workflowId: The identifier of the workflow whose events to retrieve.
send
void send(String destinationId, Object message, String topic)
void send(String destinationId, Object message, String topic, String idempotencyKey)
void send(String destinationId, Object message, String topic, String idempotencyKey, SerializationStrategy serialization)
Send a message to the workflow identified by destinationID.
Messages can optionally be associated with a topic.
Parameters:
- destinationId: The workflow to which to send the message.
- message: The message to send. Must be serializable.
- topic: A topic with which to associate the message. Messages are enqueued per-topic on the receiver.
- idempotencyKey: If
dbos.sendis called from outside a workflow and an idempotency key is set, the message will only be sent once no matter how many timesdbos.sendis called with this key. - serialization: The serialization strategy to use for this message. Defaults to
SerializationStrategy.DEFAULT, which inside a workflow uses the serialization format recorded for the sending workflow (for example, a workflow started with portable serialization sends portable messages), and outside a workflow uses the application's configured serializer.
sendBulk
void sendBulk(List<SendMessage> messages)
void sendBulk(List<SendMessage> messages, boolean sendToForks)
void sendBulk(List<SendMessage> messages, boolean sendToForks, SerializationStrategy serialization)
Send multiple messages to workflows in a single batch. Each message is delivered to its destination workflow independently; messages need not share the same destination.
Parameters:
- messages: A list of
SendMessagerecords describing each message to send. - sendToForks: If
true, also deliver each message to any forked copies of the destination workflow. Defaults tofalse. - serialization: The serialization strategy to use for all messages in the batch. Defaults to
SerializationStrategy.DEFAULT, which behaves as described forsend.
SendMessage
new SendMessage(String destinationId, Object message)
new SendMessage(String destinationId, Object message, String topic)
new SendMessage(String destinationId, Object message, String topic, String idempotencyKey)
A record describing a single message in a sendBulk batch.
Parameters:
- destinationId: The workflow to which to send the message.
- message: The message to send. Must be serializable.
- topic: A topic with which to associate the message.
- idempotencyKey: Idempotency key for exactly-once delivery; a message with a given key is sent only once.
recv
<T> Optional<T> recv(String topic, Duration timeout)
Receive and return a message sent to this workflow.
Can only be called from within a workflow.
Messages are dequeued first-in, first-out from a queue associated with the topic.
Calls to recv wait for the next message in the queue, returning null if the wait times out. If the workflow is cancelled while waiting, recv throws DBOSWorkflowCancelledException.
Parameters:
- topic: A topic queue on which to wait.
- timeout: A timeout duration. If the wait times out, return an empty Optional.
sleep
void sleep(Duration sleepduration)
Sleep for the given duration.
If called from within a workflow, this sleep is durable—it records its intended wake-up time in the database so if it is interrupted and recovers, it still wakes up at the intended time.
If called from outside a workflow, or from within a step, it behaves like a regular Thread.sleep.
Parameters:
- duration: The duration to sleep.