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

RPC with status updates? #11

Open
joelkuiper opened this issue Aug 21, 2013 · 4 comments
Open

RPC with status updates? #11

joelkuiper opened this issue Aug 21, 2013 · 4 comments
Labels

Comments

@joelkuiper
Copy link

Bit of a question, actually.

I have a service that handles long running tasks with progress reporting. Currently this works as follows: a user submits a task through POST which immediately returns a reply (in JSON) which includes a link to a web sockets url where the user can listen for updates (out of band). When the task is done the results are simply merged in with the status and pushed as a (last) status update. The client checks the JSON for the status and resolves a results future if there are results (or rejects if the task failed).

I'm looking to simplify this a bit and WAMP seems nice, however there does not seem to be an obvious way to send status updates for an RPC. Now I could just swap out the POST for a WS RPC (so that it returns a link to the status updates immediately) but it seems less than ideal. What would be your take on this?

@cgmartin
Copy link
Owner

Hi @joelkuiper , I can try to show how it could be done in clj-wamp...

https://gist.github.com/cgmartin/6302379

Here's a simple WAMP server with a long running RPC call.
The call will simulate progress status by looping/sleeping and sending a status event to a PubSub channel. When done looping the result is returned.

In the client, a button click will start a WAMP websocket connection. Immediately upon open it will subscribe to the status PubSub channel and issue the long running RPC call. A PubSub event listener on-wamp-event receives all of the progress status events.

On completion of the RPC call, the client closes the WAMP connection and the button listener is set again.

This may or may not fit with your current design, but I hope it illustrates one way it could be done in WAMP-land.

(Note: the gist is based off of code in the unreleased release-1.1 branch)

@cgmartin
Copy link
Owner

One edit/enhancement to the server long-run function...

PubSub events can target specific clients using emit-event! (vs. using send-event! which sends to all connected clients). In this example we only include the calling client using the bound *call-sess-id*, which gets set up for every RPC call.

@joelkuiper
Copy link
Author

Ah yes, that's perfect! I think I'll play around with that later today. I'll probably end up doing both this and a RESTful API. Have the relevant changes been deployed as a 1.1-SNAPSHOT or should I do a manual install first?

Many thanks 😄 !

@cgmartin
Copy link
Owner

Glad to hear! I redeployed [clj-wamp "1.1.0-SNAPSHOT"] just in case, it had been a few weeks.

You'd only need 1.1.0-SNAPSHOT if you're interested in using the ClojureScript WAMP client. The WAMP server should work fine with a similar AutobahnJS client in the current 1.0.0 release if you're wary of the snapshot version. I hope to release 1.1.0 in the next week or so. It's feature complete, just alpha testing at the moment. Cheers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants