dowjones / dj-dna-streams-javascript Goto Github PK
View Code? Open in Web Editor NEWJavaScript library for the DNA Streams API.
Home Page: https://developer.dowjones.com/
License: MIT License
JavaScript library for the DNA Streams API.
Home Page: https://developer.dowjones.com/
License: MIT License
Occasionally processes need to be restarted, but the Listener class appears to expose no way of cleanly shutting down. Forcibly shutting down introduces a risk of losing messages that are still being processed by the client, but have been ack-ed by the listener immediately after entering the onMessage function.
Having better control of ack-ing would help, but having say a shutdown method on the Listener that could be called after an appropriate signal has been received would be ideal.
Hi,
With the way the Listener class is configured, upon receiving a message it immediately performs an ack()
on the message before the message handler has been called:
const onMessage = (msg) => {
msg.ack();
return onMessageCallback(msg);
};
This is effectively telling the pubsub queue that the message has been successfully handled/processed, and that the topic can move on.
However most use cases of message processing involve an asynchronous activity (e.g. writing to another queue or database). By having the ack()
performed immediately, this means that a failure during processing the item (e.g. database down, node process crashed) would effectively mean the message could have been lost, as the library has already performed the ack()
and the pubsub queue has moved on.
By immediately ack-ing, it also removes any flow control from the client. The Listener is saying the client is ready for more, but the client could have an ever growing number of async message processing jobs still in-flight.
In these scenarios, I would have thought the ack()
call is surely more appropriate after the message processing has completed, but the Listener class does not provide such a way to do this.
My suggestions for possible implementations are:
onMessage
then acksonMessageCallback
function (the ack()
method is available as the msg object is passed through as the param)With such a setup, it removes the risk of the topic moving on without the client successfully performing its activity on the message.
A simple implementation with a callback approach could look something like:
const onMessage = (msg) => {
onMessageCallback(msg, err => {
if (!err) {
msg.ack();
} else { // some failure handling
console.err(err);
msg.nack();
}
});
};
The API could be updated in a way to make it backward compatible (e.g. additional param indicating it is async/wants to control message ack-ing).
Does this seem reasonable?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.