In the previous article, we have seen the basics of Seneca js microservice and its important features. I have provided the below link for the same.
Understanding Node Js based Microservices in Blockchain
In the era of Blockchain, where security and scalability are redefined to the next level, microservices can enhance…
Now, I will focus much more on the real development of basic microservices and its integration with API as well as intercommunication of different Microservices using Mesh Network.
I have tried simulating Hyperledger Fabric Tx flow through three modules i.e Transaction microservice, Orderer Microservice and Commit Microservice and tried showing their network communication and data sharing.
Transaction Microservice receives data from API which is sent by the user and sign to the transaction and send to the Orderer microservice for creating a simple block.
Orderer microservice creates a block and publish the data to commit microservice and now commit microservice store the transaction data into a ledger file and upon completion of operation, it will inform to Orderer Microservice and thus Orderer will inform to Transaction microservices and at the last API get the response, which completes the full cycle.
Code Set up :
Git clone from this repository which basically does the setup of express server, create default routes and has other files related to the above use case.Follow the instruction as mentioned on README.md file
Important things to understand :
Bootstrapping Mesh Network:
It basically initiates a mesh network that’s the reason it has isbase:true. There is monitor functionality which shows the real-time status of all microservices which has joined the mesh network.
Pattern Identification and Plugins:
Each Microservice is identified by pattern name e.g role:transaction,cmd:createTransaction, role:ordere,cmd:createBlock instead of calling through service discovery registry and when a new microservice join the network all other microservices will get to know its pattern through gossip protocol.
Plugins are used to bundle many functionalities of the same family e.g Under Transaction Microservice, findTransaction, createTransaction, updateTransaction could be plugins functionality expose by Transaction Microservice. Each plugin function will have a unique pattern. e.g
Integrating API to Microservice :
We need to create an instance of Seneca-mesh inside controller api and call the pattern of the desired microservice. e.g
this.add and this.act:
this is an instance of Seneca which is used to host a service or call a service. add is used for hosting service and act is used for calling a service (client service) followed by pattern.
Intercommunication of Microservices :
Data is always shared in the form of the object, each data set has transport object embedded by client service which keeps track of who has sent request, timestamp and origin of the message.
Aim of the use case and code is to provide the basic template to start to writing small microservices and understand intercommunication.
In the next part, I will try to migrate Fabric Node js SDK code to small modular microservice which looks like enrollment microservice, Transaction microservice, utility microservice which shows data relevant to block, channel or chaincode.
Microservice Template : https://github.com/spsingh559/microserviceTemplate