How would you implement a pub/sub or observable pattern in temporal?

I would like my workflows to subscribe to some service and periodically be fed data by it. Is a signal used for that?
How would I implement this pattern in temporal?

2 examples:

  1. I want my workflow to send a slack message through an activity and then receive the user’s response. E.g send a slack block containing 2 buttons ‘yes’ ‘no’ to a slack channel and then receive the answer back in the workflow through a webhook service.
  2. I want my workflow to subscribe to some topic on another service through an activity and then receive data from that topic. Then another activity would unsubscribe from that topic when my workflow ends.

Yes. You set up your webhook handler outside of Temporal, such as by using an AWS lambda function, or whatever is convenient for you. Your webhook handler would then use the Temporal client library to send a signal to your workflow.

How do you receive data using that API? Does it also send you the data that you’ve subscribed to through a webhook?

It might send the data or I might send a “data id”.
Lets take IAM for example:

  • I want some workflows to “subscribe” to some user data and then receive data only for that user.
  • The IAM has support for webhooks.
  • Say I want to do something whenever a specific user that the workflow is working on changes password.
  • So IIUC I should fire an activity that subscribes to some topic for that user password change event.
  • Then the webhook should fire a signal to all subscribed workflows.
  • When the workflow ends I should unsubscribe from that topic.

I can start a new workflow, but sometimes I want to handle an event as part of an already running workflow which has some state and context.

Using the Temporal client, you can send a signal to a running workflow by its workflow id.