IBM/Leveraging-cache-and-MessagingQueue-to-scale-BlockchainNetwork

Name: Leveraging-cache-and-MessagingQueue-to-scale-BlockchainNetwork

Owner: International Business Machines

Description: Configure Redis and RabbitMQ cluster to control the flow of incoming request to blockchain network

Created: 2018-03-26 21:04:52.0

Updated: 2018-05-22 13:24:11.0

Pushed: 2018-05-02 19:57:02.0

Homepage: https://developer.ibm.com/code/patterns/integrate-rabbitmq-and-redis-cluster-with-a-blockchain-network/

Size: 11007

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Leveraging the Cache and Messaging Queue to Scale a Blockchain Network

In this step, we will configure Redis and RabbitMQ cluster in our architecture to control the flow of incoming request to blockchain network. With the direct use of REST API calls, it is not possible to control the number of requests sent to blockchain network, this might cause errors such as read/write conflicts etc. In order to control the flow of request sent to blockchain network and scale our application, we will use RabbitMQ cluster with 3 nodes consisting of mirrored queues to queue the user requests and Redis cluster with 6 nodes (3 master and 3 slaves) where results of execution are store for a short duration. In architecture diagram, we have RabbitMQ producer present in API containers that queue the requests to RabbitMQ cluster and RabbitMQ consumers configured with an instance of Fabric-Node-SDK in Task execution containers to consume the requests from users and send it blockchain network for execution.

You will find the configuration code for Redis in ./backend/utils/util.js.

You will find the configuration code for RabbitMQ in ./rabbitClient/utils/util.js

Included Components
Application Workflow Diagram

Application Workflow

  1. Issue a git clone https://github.com/IBM/Leveraging-cache-and-MessagingQueue-to-scale-BlockchainNetwork.git.
  2. Issue the command build.sh to setup the network.
Prerequisites
Steps
  1. Run Build.sh Script to build and start the network
  2. Check the logs to see the results
  3. Test the Blockchain Network
1. Run the Build.sh Script

This accomplishes the following:

a. Clean up system by removing any existing blockchain docker images

b. Generate certificates

c. Create Peers, Orderers and Channel

d. Build docker images of the orderer, peers, channel, network

Open a new terminal and run the following command:
rt FABRIC_CFG_PATH=$(pwd)
d +x cryptogen
d +x configtxgen
d +x generate-certs.sh
d +x generate-cfgtx.sh
d +x docker-images.sh
d +x build.sh
d +x clean.sh
ild.sh
2. Check the logs

Command

er logs blockchain-setup

Output:

egistration complete
egistration complete
ult channel not found, attempting creation...
essfully created a new default channel.
ing peers to the default channel.
ncode is not installed, attempting installation...
 container image present.
: [packager/Golang.js]: packaging GOLANG from bcfit
: [packager/Golang.js]: packaging GOLANG from bcfit
essfully installed chaincode on the default channel.
essfully instantiated chaincode on all peers.
kchain newtork setup complete.

Command

er ps

Output:

fcb1e4d8        haproxy:1.7                                                                              "/docker-entrypoint.?"   5 minutes ago       Up 5 minutes        0.0.0.0:3000->3000/tcp                                rabbitclient
495511f1        backend                                                                                  "node index.js"          5 minutes ago       Up 5 minutes                                                              fitcoin_fitcoin-backend_1
04c78c40        backend                                                                                  "node index.js"          5 minutes ago       Up 5 minutes        0.0.0.0:3030->3030/tcp                                fitcoin_shop-backend_1
1c334532        rabbit-client                                                                            "node index.js"          5 minutes ago       Up 5 minutes        0.0.0.0:3003->3000/tcp                                rabbitclient3
c6cee311        rabbit-client                                                                            "node index.js"          5 minutes ago       Up 5 minutes        0.0.0.0:3002->3000/tcp                                rabbitclient2
c7cb43ca        rabbit-client                                                                            "node index.js"          5 minutes ago       Up 5 minutes        0.0.0.0:3001->3000/tcp                                rabbitclient1
3fe3a151        redis-server                                                                             "/docker-entrypoint.?"   5 minutes ago       Up 5 minutes        6379/tcp, 0.0.0.0:7000-7005->7000-7005/tcp            fitcoin_redis-server_1
40abfc4d        dev-shop-peer-bcfit-1-0e0d4e71de9ac7df4d0d20dfcf583e3e63227edda600fe338485053387e09c50   "chaincode -peer.add?"   6 minutes ago       Up 6 minutes                                                              dev-shop-peer-bcfit-1
4ddc16f4        haproxy:1.7                                                                              "/docker-entrypoint.?"   6 minutes ago       Up 6 minutes        0.0.0.0:5672->5672/tcp, 0.0.0.0:15672->15672/tcp      rabbitmq
a84a4e7c        rabbitmq:3-management                                                                    "/usr/local/bin/clus?"   6 minutes ago       Up 6 minutes        4369/tcp, 5671-5672/tcp, 15671-15672/tcp, 25672/tcp   rabbitmq2
24afd0f1        rabbitmq:3-management                                                                    "/usr/local/bin/clus?"   6 minutes ago       Up 6 minutes        4369/tcp, 5671-5672/tcp, 15671-15672/tcp, 25672/tcp   rabbitmq3
085afd54        rabbitmq:3-management                                                                    "docker-entrypoint.s?"   6 minutes ago       Up 6 minutes        4369/tcp, 5671-5672/tcp, 15671-15672/tcp, 25672/tcp   rabbitmq1
5a81c967        blockchain-setup                                                                         "node index.js"          7 minutes ago       Up 7 minutes        3000/tcp                                              blockchain-setup
6f4c90fe        fitcoin-peer                                                                             "peer node start"        7 minutes ago       Up 7 minutes        0.0.0.0:8051->7051/tcp, 0.0.0.0:8053->7053/tcp        fitcoin-peer
890f71e3        shop-peer                                                                                "peer node start"        7 minutes ago       Up 7 minutes        0.0.0.0:7051->7051/tcp, 0.0.0.0:7053->7053/tcp        shop-peer
da9fbbf6        ishangulhane/fabric-couchdb                                                              "tini -- /docker-ent?"   7 minutes ago       Up 7 minutes        4369/tcp, 9100/tcp, 0.0.0.0:9984->5984/tcp            shop-statedb
22ef3b2a        ishangulhane/fabric-couchdb                                                              "tini -- /docker-ent?"   7 minutes ago       Up 7 minutes        4369/tcp, 9100/tcp, 0.0.0.0:5984->5984/tcp            ca-datastore
ff012bbd        fitcoin-ca                                                                               "fabric-ca-server st?"   7 minutes ago       Up 7 minutes        0.0.0.0:8054->7054/tcp                                fitcoin-ca
dd0a009d        orderer-peer                                                                             "orderer"                7 minutes ago       Up 7 minutes        0.0.0.0:7050->7050/tcp                                orderer0
3cd1ba31        shop-ca                                                                                  "fabric-ca-server st?"   7 minutes ago       Up 7 minutes        0.0.0.0:7054->7054/tcp                                shop-ca
93e63b5c        ishangulhane/fabric-couchdb                                                              "tini -- /docker-ent?"   7 minutes ago       Up 7 minutes        4369/tcp, 9100/tcp, 0.0.0.0:8984->5984/tcp            fitcoin-statedb

Command

er logs fitcoin_fitcoin-backend_1

Output:

egistration complete
egistration complete
egistration complete
Awaiting RPC requests on clientClient0
Awaiting RPC requests on clientClient2
Awaiting RPC requests on clientClient1

Command

er logs fitcoin_shop-backend_1

Output:

egistration complete
egistration complete
ting socker server
Awaiting RPC requests on clientClient0
3. Test the BlockchainNetwork

In a separate terminal navigate to testApplication folder and run the following command:

install
 index.js

Navigate to url to view the blockchain blocks: http://localhost:8000/history.html

Blocks

Now navigate to url to perform operations on network : http://localhost:8000/test.html

Note : For this application the user queue value can be either : user_queue or seller_queue

Sample Enroll User request

Blocks

Sample Query request

Blocks

Sample Invoke request

Blocks

Additional Resources
License

Apache 2.0


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.