Use Durable Queues for distributed tasks
mainDBOS queues allow you to durably run distributed tasks using Postgres as the backend (no separate broker required). You can enqueue tasks from a durable workflow, and DBOS guarantees task completion and result retrieval even if the application is interrupted.
Key features include:
- Flow control (concurrency limits per queue or process)
- Task timeouts
- Rate limiting
- Task deduplication
- Task prioritization
To use queues, you must first register the queue in your main application and then use StartWorkflowOptions to associate a workflow with that queue.
// In your main
var queue = new Queue("exampleQueue");
DBOS.registerQueue(queue);
// Enqueuing a task
public void queuedTasks() {
for (int i = 0; i < 3; i++) {
String workflowId = "child" + i;
var options = new StartWorkflowOptions(workflowId).withQueue(q);
List<WorkflowHandle<String>> handles = new ArrayList<>();
handles.add(DBOS.startWorkflow(()->simpleService.childWorkflow(workflowId), options));
}
for (int i = 0 ; i < 3 ; i++) {
String workflowId = "child"+i;
var h = DBOS.retrieveWorkflow(workflowId);
System.out.println(h.getResult());
}
}