Since it was announced that tctl will be discontinued, I am searching a way to start a batch operation of type signal to notify many workflows based on a visibility query. It seems this is not really well documented as of now and therefore could anybody validate following theoretical code snippet?
var startBatchOperationResponse = WorkflowServiceStubs.newServiceStubs(
WorkflowServiceStubsOptions.newBuilder()
.setTarget("temporal.url")
.validateAndBuildWithDefaults())
.blockingStub()
.startBatchOperation(StartBatchOperationRequest.newBuilder()
.setVisibilityQuery("WorkflowType = \"namespace.MyWorkflowType\" and ExecutionStatus = \"Running\"")
.setSignalOperation(BatchOperationSignal.newBuilder()
.setSignal("MySignalMethod")
.setInput(Payloads.newBuilder()
.addPayloads(new JacksonJsonPayloadConverter()
.toData(myObjectPassedAsFirstParameter)
.orElse(null))
.build()))
.build());
Assumptions:
- To be run from an activity
-
myObjectPassedAsFirstParameter
must be serialisable using the JacksonJsonPayloadConverter
All this seems a bit too much of boilerplate, so if there is any other technique to send a signal to many workflows, I am in.
Typical use case and motivation:
Temporal allows to replace event sourcing and may therefore simplify architecture. There are situations where this becomes difficult, typically when several clients need to receive a notification that some state changed. A possible workaround is to represent a client subscription to some state by a workflow that does nothing except waiting to receive a signal in case the state changes. Instead of explicitly registering such observers in whatever collection, the idea is to rely on temporal visibility and distribute a signal to all workflows based on a specific query. There are of course downsides such as need of cleaning the observer workflows and possible performance hit in case of larger number of those observers.