The assignment is to build a simple Producer/Consumer system. In this system the Generator (Producer) will send a series of random arithmetic expressions, while the Evaluator (Consumer) will accept these expressions, compute the result and then report the solution to the Generator (Producer).
- Run
npm install
- Optionally edit
config.js
to define a custom host, port, and other basic options
- Run
npm test
- Watch the magic happen
The Consumer listens for requests containing an expression
POST parameter, parses the mathematical expression, evaluates it, and responds to the requester with the answer (or error). All incoming requests to the Consumer are logged to the console, as are the answers for each expression.
- Run
npm run consumer
- Optionally make a POST request to http://localhost:7000/ using Content-Type
application/x-www-form-urlencoded
orapplication/json
with anexpression
payload (e.g. 2+3=)
An instance of the Producer will form an expression consisting of 2 random integers and a random mathematical operator (+, -, *, /) at a rate of once per second (unless otherwise specified via an environment variable or by altering the config.js
file). After constructing each random expression, it will attempt to send it to the Consumer via an HTTP POST request to be evaluated and receive an answer. Each generated expression is logged to the console, as are the answers received from the Consumer. You may run multiple instances of the Producer at a time.
- Run
npm run producer
- Repeat for as many Producer instances you would like to run simultaneously
- Node.js >= 0.10.42
- NPM >= 1.4.29
- Async 1.5.2
- body-parser 1.15.0
- connect 3.4.1
- log4js 0.6.31
- request 2.69.0
- Mocha 2.4.5
- Sinon-Chai 2.8.0