A simple and lightweight ESB message processing engine for Node
Why?
Because complex processing logic including call to third party systems in Node SHOULD be easy
Installation
npm install light-esb-node
Usage
To use, simply create components, wire them up and start sending messages to be processed.
Core concepts
- Message - Javascript object that is being processed by Components
- Component - atomic service that takes Message as input, processes the Message and returns resulting (usually modified) message as result
- Flow - chain of Components fulfilling processing of some integration/orchestration logic (transform data, call third party services)
Create a component
var ESB = ; // this will be invoked either when there is an error during component processing or when the ResultComponent is reached{ iferror console; else console; } var component = ESB;
Wire up components (component might wire more then one destination)
var component = ESB;var receiver1 = ESB;var receiver2 = ESB; // when component finishes processing the message the result will be passed by to the receiver1 component and receiver2 component for further processingcomponent;component;
ESBMessage structure
/** * Represents a ESB Message being processed by components. * * @param * @param * @param * @param * @type */var { thispayload = payload; thiscontext = createdTimestamp: Date correlationId: uuidGenerator caller: user: callerUser system: callerSystem correlationId: callerCorrelationId ; thisoriginalPayload = ; thisvars = {};}
Initiate processing - sending input message to the flow
var component = ESB; // prepare input message and start processingvar ESBMessage = ESB;component;
Store message payload for further processing
// the message object from now on will be enhanced with the new entry in the vars section (vars.customerData) of the ESBMessagevar component = ESB;
Restore message payload for processing
// from now on, the payload of the ESBMessage that will be processed by next component in the flow will be replaced with contents of the vars.customerData objectvar component = ESB;
Set payload to a custom object
// message payload will be replaced with the provided object, one may use reference to the original message fields using '$' notionvar c21 = ESB;
Merge data from vars storage with payload of the currently processed message
// now some merging of messages, contents of vars.customerInfo will be merged into processed message payloadvar component = ESB;
Transform payload
// the message that reaches this component will be altered by mapping provided - see object-mapper npm module documentation for details how to build mapsvar component = ESB;
Call external HTTP services (POST, GET)
// now it is time for some third party calls, call external REST servicevar component1 = ESB;var component2 = ESB;// DELETE call examplevar c22 = ESB; // full call using path parameter (${postId}), dynamic query params (?param1=) - using '$' reference to message contents and basic authvar c20 = ESB;
Content based routing - redirect messages to the appropriate channel based on message contents
// route component - based on ESBMessage.context field values the message will be routed to the appropriate named channelvar c17 = ESB; // for router component connected components MUST be connected using channel namesc17;c17;
Freestyle - component that accepts any custom processing script
// script component with custom processing functionvar c19 = ESB;
Return results - at the end of the processing flow
// at the end of the flow return resulting message - esbCallback function will receive the resulting message objectvar component = ESB;
Sample
For a sample flow check samples folder.
Debugging/Console Out
debug module)
Using Node environment variables (plays nicely with the hugely popular// Set the DEBUG environment variable to enable debug output of Light-Esb-Node
// show components initialization
//process.env.DEBUG = 'esb:core, esb:component';
// show components processing messages
//process.env.DEBUG = 'esb:messages';
// show details of remote calls of components
//process.env.DEBUG = 'esb:calls';
// show all
process.env.DEBUG = 'esb:*';
Changelog
- v1.2.4 - fixed Basic Auth problem
- v1.2.3 - added DELETE support in CallComponent
- v1.2.2 - added PayloadComponent and support for dynamic parameters in CallComponent
- v1.0.2 - added Route and Script components
- v1.0.0 - initial version