Send Signal to Workflows
Infinitic is still in active development. Subscribe here to follow its progress.
It is possible to send a signal to running workflows. Sending signals is done through channels that must be described in the workflow interface, for example:
public interface HelloWorld {
SendChannel<String> getNotificationChannel();
String greet(@Nullable String name);
}
interface HelloWorld {
val notificationChannel: SendChannel<String>
fun greet(name: String?): String
}
This signal can be any serializable object of the type described in the workflow interface.
We can send an object to a running instance targeted by id:
// stub targeting a running HelloWorld workflow with a specific id
HelloWorld helloworld = client.getWorkflowById(HelloWorld.class, "05694902-5aa4-469f-824c-7015b0df906c");
// send a signal to this instance through a channnel
helloworld.getNotificationChannel().send("foobar");
// stub targeting a running HelloWorld workflow with a specific id
val helloworld: HelloWorld = client.getWorkflowById(HelloWorld::class.java, "05694902-5aa4-469f-824c-7015b0df906c")
// send a signal to this instance through a channnel
helloworld.notificationChannel.send("foobar")
or running instances targeted by tag:
// stub targeting running HelloWorld workflows with a specific tag
HelloWorld helloworld = client.getWorkflowByTag(HelloWorld.class, "foo");
// send a signal to those instances through a channnel
helloworld.getNotificationChannel().send("foobar");
// stub targeting running HelloWorld workflows with a specific tag
val helloworld: HelloWorld = client.getWorkflowByTag(HelloWorld::class.java, "tag")
// send a signal to those instances through a channnel
helloworld.notificationChannel.send("foobar")