4ib3r / StompBrokerJS

NodeJS StompBroker
MIT License
35 stars 66 forks source link

Add mechanism for hooking custom command middleware #16

Closed starstuck closed 5 years ago

starstuck commented 6 years ago

StompServer offers events as a way to trigger custom behaviour when broker is processing a command. Unfortunately this does not give an event handler an opportunity to affect command processing flow, which makes it unsuitable mechanism to implement authentication/authorisation.

In this pull request I am proposing alternate solution for hooking up middle-ware functions for command handlers. You can register multiple middle-ware and they will be processed in order. Each middle-ware takes full responsibility of execution flow, and can decide to call next() middle-ware in chain, or respond with error. The mechanism of chaining middle-ware allows for having asynchronous code inside them.