Objective of this project is to replace polling strategy with event based stragy using WebSockets.
- Working nodejs v12.x
- AWS Profile
- yarn
There are 3 parts of this project. Market
where orders come in, Server
where orders are processed and Portal
where orders are monitored.
-
Clone project
-
Inside the project run
yarn
to install depencies. -
Create
config.yml
.copy config.sample.yml config.yml
-
Edit
config.yml
and change the values for REGION and PROFILE. -
Create database in AWS:
yarn workspace resources setup dev
-
Go to AWS -> DynamoDB ->
order-status-ws
and copy theLatest stream ARN
. -
Edit again
config.yml
and paste the value ofORDER_TABLE_STREAM_ARN
from the previous step. -
Deploy WebSocket server.
yarn workspace server deploy dev
-
From the previous step, copy the endpoint that starts with
wss://
. Create the fileportal/.env.local
with the contents below:REACT_APP_WS_ENDPOINT=wss://xxxxxxxxxx.execute-api.ap-southeast-1.amazonaws.com/dev
-
From step #8, copy the endpoint that starts with
https://
. Create the filemarket/.env.local
with the contents below:REACT_APP_API_ENDPOINT=https://xxxxxxxxxx.execute-api.ap-southeast-1.amazonaws.com/dev/order
-
Start Portal app
yarn workspace portal start
-
On a differnt terminal, start Market app
yarn workspace market start
-
Go to
http://localhost:9001/
. Enter Company and Outlet ID then connect. The status should become connected. -
On another browser tab, go to
http://localhost:9002/
. Fill in the details. Make sure Company and Outlet ID matches the one in the Portal. Click send. -
The Portal should receive the order status data similar below:
{ "type": "new-order", "orderId": "1", "status": "Submitted" }
-
Open mutiple tabs/browsers and go to
http://localhost:9001/
/. Get them all connected with different/same company and outlet id. -
Send different data from Market to experiement with the project.
yarn workspace server delete dev
yarn workspace resources delete dev