simple-producer-consumer
v1.2.2
Published
A simple demo of producer and consumer node.js services
Downloads
5
Readme
simple-producer-consumer
A project to demonstrate bi-directional asynchronous network communication between independent Node.js processes.
A generator
process creates random arithmetic expressions of 1 to 3 operations (2 to 4 operands)
and sends the JSON formatted representation of the expression to an evaluator
process which
computes the value and replies to the generator
. The generator and the evaluator communicate via
websockets (facilitated by the Socket.io library).
Demonstration
Requirements
- Node.js v4.0.0 or later
Usage
Option 1 - Run generator and evaluator processes locally on same machine
# Install the npm module globally (may need to run as root via sudo)
$ npm install simple-producer-consumer@latest -g
# Start the evaluator process
$ spc-evaluator
# Start the generator process (in a different terminal window)
$ spc-generator
Option 2 - Run the generator and connect to a hosted evaluator process running on an AWS EC2 server
# Install the npm module globally (may need to run as root via sudo)
$ npm install simple-producer-consumer@latest -g
# Start the generator process (in a different terminal window)
$ SPC_SERVER_HOST=ec2-52-35-48-3.us-west-2.compute.amazonaws.com spc-generator
Option 3 - Clone the repo, build the module and run without installing globally on your system
$ git clone [email protected]:cflynn07/simple-producer-consumer.git
$ cd ./simple-producer-consumer
$ npm install .
# Start the evaluator
$ npm run evaluator
# Start the generator
$ npm run generator
Tests
Unit tests use Mocha, Unit.js and Istanbul
$ npm run test
$ npm run test-html-cov # Will auto-open Google Chrome with test coverage data on OSX
Configuration
Configuration options can be overriden by enviroment variables. Default values are defined in
configs/.env
SPC_EXPRESSION_DISPLAY_COUNT=10
SPC_GENERATOR_INTERVAL=250
SPC_LOG_LEVEL_STDOUT=none
SPC_SERVER_HOST=localhost
SPC_SERVER_PORT=3001
UML Diagrams
Sequence
License
MIT