title: Enqueue Workflows from External Applications impact: MEDIUM impactDescription: Lets other services trigger durable workflows without hosting them tags: client, enqueue, external, EnqueueOptions, integration
Enqueue Workflows from External Applications
DBOSClient.enqueueWorkflow submits a workflow to a queue by name, so an API server can hand work to a separate
processing service without linking against its code. The client is outside the application, so workflow name, class
name, and queue must be given explicitly.
Incorrect (an ad-hoc job table):
// Custom polling, retry, and status plumbing — exactly what DBOS queues provide
jdbc.update("INSERT INTO job_queue(payload, status) VALUES (?, 'pending')", payload);
Correct (enqueue through DBOSClient):
import dev.dbos.transact.DBOSClient;
import dev.dbos.transact.EnqueueOptions;
import dev.dbos.transact.workflow.QueueName;
import dev.dbos.transact.workflow.QueueOptions;
try (var client = new DBOSClient(dbUrl, dbUser, dbPassword)) {
// Optionally register the queue from the client (persists to the system database)
client.registerQueue("pipelineQueue", new QueueOptions().withConcurrency(10));
var options = new EnqueueOptions(
"dataPipeline", // workflow name
"com.example.DataPipelineImpl", // class name (or @WorkflowClassName value)
QueueName.of("pipelineQueue")) // queue
.withWorkflowId(requestId) // idempotency key
.withPriority(10);
WorkflowHandle<String, Exception> handle =
client.enqueueWorkflow(options, new Object[] {"task-123", "data"});
String workflowId = handle.workflowId();
String result = handle.getResult(); // optional: wait for completion
}
The queue does not need to exist when enqueueWorkflow is called. If no queue with the given name has been
registered, the workflow is still durably recorded as ENQUEUED and starts running once the queue is registered and
a worker becomes available.
EnqueueOptions is the top-level dev.dbos.transact.EnqueueOptions, shared by DBOSClient.enqueueWorkflow and
dbos.enqueueWorkflow. The constructors fix what to run and where, with the queue as a QueueName:
(workflowName, queue), (workflowName, className, queue), and (workflowName, className, instanceName, queue).
There is no withClassName or withInstanceName. A Java workflow is identified by its class, so always pass the
fully qualified name of the implementing class (or its @WorkflowClassName value) when targeting a Java workflow;
omit it only for a workflow not registered on a class, such as a Python workflow function. A Java executor that
dequeues a workflow enqueued without a class name cannot run it: it fails with
DBOSWorkflowFunctionNotFoundException and the workflow stays PENDING, as for any unregistered workflow. The nested
DBOSClient.EnqueueOptions, and the client overloads that take it, are deprecated for removal since 1.1 — do not use
them. Options:
withWorkflowId(String)— idempotency keywithAppVersion(String)— pin the application version that should process the workflow; left unset, the owning application’s latest version dequeues itwithApplicationName(String)— the application that owns and runs the workflow (default: the client’s own, or unclaimed for an unnamed client) (advanced-shared-database.md)withTimeout(Duration | long, TimeUnit | Timeout)/withNoTimeout()— an explicit timeout is timed from dequeue. Withdbos.enqueueWorkflow, an unset timeout takes the bound of an enclosingWorkflowOptionsblock if there is one; otherwise, inside a workflow, it inherits the caller’s deadline (1.2+), so the child cannot outlive it.withNoTimeout()declines both. From aDBOSClient, unset means none (workflow-timeout.md)withDelay(Duration).withDeadline(Instant)is deprecated for removal since 1.2 — use a timeoutwithDeduplicationId(String)/withPriority(Integer)/withQueuePartitionKey(String)withSerialization(SerializationStrategy)— usePORTABLEfor cross-language argumentswithAttributes(Map<String, Object>)— searchable metadatawithAuthenticatedUser(String)/withAssumedRole(String)/withAuthenticatedRoles(String...)/withAuthentication(user, roles...)
Arguments are passed as an Object[] and serialized, so they must match the workflow method’s parameters and be
JSON-serializable. To call a workflow implemented in Python or TypeScript, set
withSerialization(SerializationStrategy.PORTABLE) and, for named arguments, use enqueueWorkflow(options, positionalArgs, namedArgs); named arguments without PORTABLE throw IllegalArgumentException
(advanced-interops.md).
Inside a DBOS application, dbos.enqueueWorkflow(options, args) and dbos.enqueueWorkflow(options, positionalArgs, namedArgs) take the same EnqueueOptions to enqueue a workflow the application has no reference to.
Not available in Java: a return-existing deduplication policy (a colliding deduplication ID always throws
DBOSQueueDuplicatedException), a per-enqueue maximum recovery attempts, and enqueueing inside a caller-owned
database transaction.
Always close() the client when done.
Workflows can also be enqueued straight from PostgreSQL — for example from a trigger — with the system database
function dbos.enqueue_workflow(workflow_name, class_name, queue_name, positional_args).
Reference: enqueueWorkflow