- 1. Overview Architect
- 2. Local setup
- 3. CURL command for REST API
- 4. Run
Jesttest - 5. Source structure
- 6. Sequence diagram in some use cases
- orchestrator-service: It gathers all APIs from others
product-service,search-service,checkout-service. It will be mainly used as endpoints for users or frontend services. This service is also a producer to receive mesage and send checkout data message to Message MQ. Thecheckout-serviceas consumer, it will read messages from Rabbit MQ, they are persisted into MongoDB. - search-service: It provides search and sort functionality for products.
- product-service: Service relates to add and delete products.
- checkout-service: It is relevant to payment and checkout.
- service-registry: It is central service and help to keep track of other services such as register or unregister once we start or stop service.
- Start
MongoDBdocker-compose
cd etc/mongo-docker/
# Create and start containers
docker-compose up -d --build
# Display services
docker-compose ps
# Stop services
docker-compose stop
# Start services
docker-compose start
# Stop and remove containers, networks, images, and volumes
docker-compose down -v- Use
Robo 3Tto accesss MongoDB with defaut db name and account
db.createUser(
{
user: "admin",
pwd: "admin",
roles: [
{
role: "readWrite",
db: "my-mongo-db"
}
]
}
)- Start
RabbitMQdocker
docker run -it --rm --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3-management- Start
service-registry
cd service-registry
npm run start- Start
search-service
cd search-service
npm run start- Start
product-service
cd product-service
npm run start- Start
checkout-service
cd checkout-service
npm run start- Start
orchestrator-service
cd orchestrator-service
npm run start- Insert products into
Producttable
curl -X POST --header "Content-Type: application/json" --header "Accept: application/json" -d @etc/product_insert.json "http://localhost:3080/products"- List all products
curl -X GET --header 'Accept: application/json' 'http://localhost:3080/products' | jq .- Search products by name
curl -X GET --header 'Accept: application/json' 'http://localhost:3080/products?name=name1&sort_by=name' | jq .- Search products by name with operator
curl -X GET --header 'Accept: application/json' 'http://localhost:3080/products?name=eq:name1' | jq .
[
{
"_id": "609de68be9d8da4a94453107",
"name": "name1",
"price": 2,
"branch": "Branch Test",
"color": "Testing",
"__v": 0
}
]- Search products by name with operator and sort by price on ascending order
curl -X GET --header 'Accept: application/json' 'http://localhost:3080/products?price=gt:1&sort_by=-price' | jq .- Delete products
curl -X DELETE --header "Content-Type: application/json" --header "Accept: application/json" -d @etc/product_delete.json "http://localhost:3080/products" | jq .- Send data checkout to Message MQ, data will be populated and upserted into
Paymentstable
curl -X POST --header "Content-Type: application/json" --header "Accept: application/json" -d @etc/checkout_send.json "http://localhost:3080/checkout" | jq .- Search all payments
curl -X GET --header 'Accept: application/json' 'http://localhost:3080/payments' | jq .- Search payments by product name
curl -X GET --header 'Accept: application/json' 'http://localhost:3080/payments?productName=eq:product%203' | jq .
[
{
"_id": "609de7b6f3255553dc410746",
"userName": "dat",
"orderId": 3,
"productName": "product 3",
"quality": 1,
"price": 500,
"__v": 0
}
]- Search payments by product name and sort price on ascending order
curl -X GET --header 'Accept: application/json' 'http://localhost:3080/payments?productName=5&sort_by=-price,orderId' | jq .- Delete payments
curl -X DELETE --header "Content-Type: application/json" --header "Accept: application/json" -d @etc/checkout_delete.json "http://localhost:3080/payments" | jq .- Make sure we start services
service-registry,search-service,product-service,checkout-service, we can stop serviceorchestrator-servicein this case. Also start MongoDB and Message MQ. - We have 2 test suits in
tests/payments.test.jsandtests/product.test.js
# start all services before run jest test
cd orchestrator-service
run npm test- In every service, type the following command line
npm run lint
npm run lint:fix- Most of service have a similar structure, it includes
srcandtestsfolder. - Currently we only focus testing on
orchestrator-service, a full flow from orchestrator-service to backend and database.
axios: A promise based HTTP clienbunyan: A JSON logging library for node.js servicesmongoose: A MongoDB ODMamqplib: Library for message broker, RabbitMQhttp-errors: Create HTTP error objectssemver: The semantic version parser.
- To simplify the persistent we just have 2 tables (collections) in MongoDB,
ProductandPayment. - These collections dynamiclly created by using ORM mongoose once run services.
- Currently, most of backend services are using ORM persistence including
search-service,checkout-service,product-service - Here are schemes
const productSchema = new mongoose.Schema({
name: String,
price: Number,
branch: String,
color: String
});
const paymentSchema = new mongoose.Schema({
userName: String,
orderId: Number,
productName: String,
quality: Number,
price: Number
});



















