Quick update on this thread as it has generated some good discussion.
I've made some good progress on the design and now also have a fully working implementation. Which is nice.
The hook names have been updated to better reflect what they are for and to be more consistent around the use of the on
/pre
/post
prefixes.
preSend
->
onSend
- passed an array ofSendEvent
objects. The messages inside these objects are exactly what the node has passed tonode.send
- meaning there could be duplicate references to the same message object.preRoute
- called once for each SendEvent object in turnonSend
->
preDeliver
- the local router has identified the node it is going to send to. At this point, the message has been cloned if needed.postSend
->
postDeliver
- the message has been dispatched to be delivered asynchronously
(unless the sync delivery flag is set, in which case it would be continue as synchronous delivery)onReceive
- a node is about to receive a messagepostReceive
- the message has been passed to the node'sinput
handleronDone
,onError
->
onComplete
- the node has completed with a message
I've also:
- updated the design note with some more details on the new
RED.hooks
api this will introduce. - added some words to explain the difference between
RED.events
andRED.hooks
as they look similar but serve different purposes.
Some links
- Design Note PR: Pluggable message routing by knolleary · Pull Request #7 · node-red/designs · GitHub
- Direct link to the design note: https://github.com/node-red/designs/tree/message-routing/designs/pluggable-message-routing
- Draft PR that implements this current design - Pluggable Message Routing by knolleary · Pull Request #2665 · node-red/node-red · GitHub
I am still looing at how these hooks can be extended to other parts of the lifecycle - starting/stopping/deploying etc - as that will be needed by components such as custom routers or the flow debugger. The question remains whether they will be hooks (which can modify the data passing through) or events (which are outside observers to the data).