Skip to content

Dynamic worker connection and queue#326

Closed
janwehner wants to merge 4 commits intodurable-workflow:masterfrom
janwehner:poc-db-queue-connection
Closed

Dynamic worker connection and queue#326
janwehner wants to merge 4 commits intodurable-workflow:masterfrom
janwehner:poc-db-queue-connection

Conversation

@janwehner
Copy link

Hi,

This PR is more kind of a proof of concept. It does introduce the possibility to set the queue and connection name dynamically.

It's currently not possible to really set the queue connection and queue name dynamically. There is this discussion were was suggested to extend the workflow and only set the $connection and $queue property.

The problem is that I have about 40 workflows and would like to introduce a tenant-based queue system and it's not really reasonable to create hundreds of classes only to define the $connection and $queue property.

The second approach to let the parent workflow inject the queue in every activity and child workflow it is spawning does not work because the Signal, Timer, Exception and ChildWorkflow classes do get the connection and queue from the default properties of the workflow and would be processed by the wrong worker or not at all.

Since an instance of the StoredWorkflow class is available in every workflow-related class it would be the easiest way to introduce dynamic connection and queue names by saving them in the database.

The PR is adding two optional parameters to the WorkflowStub::make method to save the connection and queue name in the database. Doing so is passing the connection and queue completely down the line by minimal changes to the dispatching of jobs and making of child workflows and activites, so even Signal, Timer, Exception and ChildWorkflow will be processed by the correct worker.

I think this approach would have no impact on existing systems since the $connection and $queue property would still be used if no connection and queue is set in the database.

Would you consider merging/implementing this approach for dynamic connection and queue names?

@janwehner janwehner force-pushed the poc-db-queue-connection branch from 0d5b84f to e8dee83 Compare February 19, 2026 14:49
@rmcdaniel
Copy link
Member

@janwehner
I like your idea. I think we could avoid the migration by storing the connection and queue options as part of the arguments. We could do a little bit of magic to make it backwards compatible too. I would make a WorkflowOptions class that lets you set workflow options and if you pass it into the start() method it takes effect.

$workflow->start('blah', 'blah', WorkflowOptions::set(['connection' => 'connection-name', 'queue' => 'queue-name']));

Would this work for you?

@janwehner
Copy link
Author

Yea, that should work. So the only difference would be the connection and queue options saved in the arguments column instead of seperate columns and no changes to the WorkflowStub::make method are necessary right? Sound even better than my approach.

@rmcdaniel
Copy link
Member

I will make a new PR for this feature. Thanks for your work!

@rmcdaniel rmcdaniel closed this Feb 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments