-
Notifications
You must be signed in to change notification settings - Fork 5
Description
A nice feature would be "middleware"-style handlers (similar to beforeSend and beforeRetry) that get called before any of the ack/reply handlers are called.
My use case is that I am adding latency profiling for all incoming API requests (through Rocky). If a request requires a message to be sent to the device before it can complete, then I'd like to capture the RTT from Agent-->Device-->Agent (for both reply and ack).
To accomplish this today, I'd have to add in the latency calculation to every API route handler that sends a message to the device through MessageManager, which isn't very maintainable.
I thought that I could add this into the global MessageManager.onReply and MessageManager.onAck handlers, but those get called after the corresponding message-specific handlers, and at that point the API request has already been completed. So, rather than change the order of those calls (which I think should remain the way they are), my current solution is to use beforeOnReply and beforeOnAck "middleware" to add profiling data to the response headers before the API request is complete.