The Micros-Framework
The programming approach to create software that is lightwight in development and has less cross dependencies to build anti-monolitic software. Each programming feature stands alone with his own dependencies (as a module) and redirects to other modules to complete the main process. The concept follows a simple pipe that is optionally splitted in multiple sub-pipes to process parallel working tasks and combine all sub results for further processing. You can switch between different communication models like http or websockets. This Framework is inspired by Express (Connect), the MicroService growth and message passing interfaces (like scatter, gather, accumlators and broadcasts). Each process is a predefined chain that describe the data flow throught the modules. The last module must output the result in different ways. This framework is a product from the Bachelor Thesis Social Media Recommendations from Francesco Möller, Josua Koschwitz and Maximilian Stroh.
Create a MicroService
TL;DR: Here is a short example for a MicroService that add two numbers or accumulate over multiple numbers (sum):
# Create a new MicroService MicroService = require'micros'MicroServiceadd = 'add' # Create a new MicroService with a given name add$set 'api''ws' # Set the API on websockets # Define the Runtime # Standard Addition = # The method definition like an Express middleware next req + params0req + params0 # An accumulator or sum = res = reqreduce val + akk0 next resres # A minimum function over all incoming numbers = res = reqreduce if val < akk then val else akkreq0 next resres # Install the runtime add$install runtime ## Module Export module.exports = add
All MicroServices will be included with require
and can be used in chains and other features. The method next
calls the next MicroService of the underlying chain. For better functional support you can get the chain context in which the MicroService was called from next
with next.chain
for all further coming services and next.previous
for the previous MicroService. You can call next
with multiple request objects to differ data for next broadcast or an accumulate.
If there exist only one request object for a upcoming broadcast, all MicroServices from the broadcast gets the same request:
next req1req2req3reqnres # Multiple requests for Broadcast # or next reqres # Only one request for all Broadcast links
Their always exist one response object with excepttion for an previous accumulate from a broadcast.
Chains
The chains are valid CoffeeScript but can read as a flowing pipe. Begin the chain at your desire:
chain1 = m1 -> m2 -> m3 -> m4 -> m5chain2 = -> m1 -> m2 -> m3 -> m4 -> m5chain3 = Chain -> m1 -> m2 -> m3 -> m4 -> m5chain4 = m1 -> m2 -> m3 -> m4 -> m5
Defining Splitters: Splitters can be: Scatters, Broadcasts, variable Scatters, variable Broadcasts
chain = m1 -> m2 -> Splitter m5
You can include Chains in Chains:
inner_chain = -> m2 -> m3 -> m4chain = m1 -> inner_chain -> m5
Use custom MicroService methods to better control your level of abstraction:
chain = -> m1 -> m2method -> m3 -> m4
Use parameters for better variation (works also with service methods).
This parameters cames from the described chains and can be found in params
from MicroService method definitions:
chain = m1 3-> m2method -> m3method 'msg'-> m4 -> m5
An alternative parameter syntax is in various situations better to read:
chain = m1 m2method -> m3method m4 -> m5
Graphics coming soon
Example App
The following example shows how to use the predefined MicroServices:
Micros = require 'micros'MicroService = MicrosMicroServiceChain = MicrosChainSplitter = MicrosSplitter # Configure MicroService Microsset 'ms_folder''services' # Define the MicroService folder (Default is 'node_modules') # Spawm services Microsspawn # Spawn all processes with are corresponding API interface eval " = service" # register the services in global scope ### There exist three MicroService examples: inc, add, print inc: increase the number with one add: adds two numbers print: print the number on stdout### = -> # Define Chain 1 inner_chain = inc -> inc -> inc chain = add inner_chain -> add print chainexec 2 # Define Chain 2 with a splitter splitter = inner_chainincadd2 chain = add splitter -> addsum -> print chainexec 5 setTimeout cb2000
Messages
The Inter Communication Message (ICM) from MPI's are use to send information between MicroServices. The messages are described in JSON and are planned with other formats in the future (like ProtoBuf).
message = request: ... # The Request Object with processing parameters response: ... # The Response Object with processing results chain: ...# The further chain sender: 'sender' # The senders $module_name params: ...# As Array (optional) method: 'method' # The MicroService method (optional) gather: # Used for Gather the same chain over multiple requests (optional) key: 'd6sd436' services: 5 # Service counter