Async function for queue subscribe
See original GitHub issueIs there a way to use async functions in subscribers? I’m looking for a way to do this:
let sub3 = await nc.subscribe('foo.baz.>', async (err, msg) => {
// await async task to finish before taking next item in the queue...
}, {queue: 'A'});
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Async function for queue subscribe · Issue #39 · nats-io/nats.ts
Is there a way to use async functions in subscribers? I'm looking for a way to do this: let sub3 = await nc.subscribe('foo.baz.>...
Read more >JS async / await tasks queue - javascript - Stack Overflow
enqueue () returns a new Promise , that will be resolved(or rejected) at some point later. This Promise can be used to handle...
Read more >03 - Exploring Async.js - async.queue - YouTube
... donating: https://www.paypal.me/pentacode We're going to explore async. queue function to help us process ... Don't forget to subscribe !
Read more >Async - OpenFaaS
The queue-worker acts as a subscriber and deserializes the HTTP request and uses it to invoke the function directly. The asynchronous workflow can...
Read more >Mutiny - Async for bare mortal - Quarkus
Subscribing triggers the operation. The subscription method can also define handlers: the id value on success, or a failure when the insertion fails....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Here’s an example of what that would look like:
https://gist.github.com/aricart/0e0641468694ac451592765feea84835
@haywirez thanks for the clarifications, you are effectively describing a work queue. Implicitly it seems that you require in-order processing. The payload I take it is very small. Really what you are looking for is store-and-forward, but have the client be in control of the ‘next’ message.
Just to make sure we are on the same page, a NATS subscription doesn’t hold any sort of queue in the server. So while you want to only ‘take’ the next message, all messages for the subscription are already in the client’s message buffer. If the client were to fail, the messages would be lost.
You could take a look at node-nats-streaming - that will get you somewhat close. You would have to configure the streaming server a bit differently from what a normal configuration is:
ackWait
to the maximum amount of time decoding would take + extra.Now your client can process the message, and when done processing ack it (if not acknoledged it will receive the message again, or if in a queue group, a different client could be assigned the message).
This will get you much closer to what you are trying to do, but there may be additional gotchas. @kozlovic can probably inject additional wisdom.