Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add SSE example #287

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Conversation

nubunto
Copy link

@nubunto nubunto commented Aug 23, 2023

What was changed

Added a very simple SSE sample.

Why?

Seems like something people usually want to know how to work out.

@CLAassistant
Copy link

CLAassistant commented Aug 23, 2023

CLA assistant check
All committers have signed the CLA.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@mjameswh
Copy link
Contributor

mjameswh commented Sep 1, 2023

Great! Thanks @nubunto for contributing this sample.

I think we really need to demonstrate this concept in a setup that supports the possibly of having more than one HTTP server running at the same time. The main difficulty in that case is that the activity task to send a message to user/connection X need to be routed to the appropriate activity worker, ie. the one that lives in the process that own that HTTP connection.

Implementation wise, this is not very complex (per host task queue), but that requires that workflows sending messages knows the list of user/activity task queues to which they need post messages.

What I have in mind would be to have something like a "Chat Room Workflow". When establish an SSE connection, the user would have to tell the name of the chat room it want to join (eg. to make it easy, that could be a segment of the URL). The HTTP handler add the connection to its local pool of SSE connection, then do signalWithStart to the appropriate chat room workflow execution (ie. workflow id is derived from chat room name), and send its task queue name + some form of user identifier as argument on the subscribe signal.

What do you think?

@nubunto
Copy link
Author

nubunto commented Sep 5, 2023

that was on the back of my mind as I finished and tested the implementation, and I think it's very reasonable! I'll update the PR accordingly as soon as I have the time!

@nubunto
Copy link
Author

nubunto commented Sep 5, 2023

Another possible way of achieving the same end result of horizontally scaling the HTTP server is by leveraging something like Redis pub sub as a lightweight message broker. Usually this is not what I'd do if I'm going for durability, but since the message publishing is backed by Temporal it might be an relatively lightweight solution.

@nubunto
Copy link
Author

nubunto commented Dec 30, 2023

@mjameswh I implemented your suggestion! took me a while, sorry about that. Please, take a look whenever possible and let me know what you think!

@mjameswh
Copy link
Contributor

mjameswh commented Jan 3, 2024

Great! Will try to review by the end of this week. Thanks for your work on this.

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.

3 participants