- Implement 2 services:
order-service
&store-service
- The first service
order-service
should receive a request via gRPC and send data to Kafka
message CreateOrderRequest{
int64 user_id = 1;
int64 item_id = 2;
}
message CreateOrderResponse{
string message = 1;
}
- The second service
store-service
should reviece a message from Kafka and write it to PostgreSQL
CREATE TABLE IF NOT EXISTS store (
id SERIAL PRIMARY KEY,
user_id BIGINT NOT NULL,
item_id BIGINT NOT NULL,
created_at DATE DEFAULT CURRENT_DATE
);
git clone https://github.com/pintoter/mts-test.git
- Create .env file with filename ".env" in the project root and setting up environment your own variables:
DB_USER = postgres
DB_PASSWORD = 123qweASD
DB_PORT = 5432
DB_NAME = store
- Create .env file with filename ".env" in the
store-service
root and setting up environment your own variables:
# Database
DB_USER = username
DB_PASSWORD = password
DB_HOST = "localhost"
DB_PORT = 5432
DB_NAME = "store"
DB_SSLMODE = "disable"
Hint: if you are running the project using Docker, set
DB_HOST
to "store-service-postgres" (as the service name of Postgres in the docker-compose).
- Compile and run the project: For starting:
make version=prod
- To test functionality, you can open
Postman
and create request to order-service:0.0.0.0:8001
Access to Kafka-UI: http://localhost:8080/ .
- Example request in Postman:
{
"item_id": "1",
"user_id": "10"
}
- Example response in Postman:
{
"message": "Your order has been successfully created!"
}
- Example record in PostgreSQL:
| id | user_id | item_id | created_at |
| -- | ------- | ------- | ---------- |
| 1 | 10 | 1 | 2023-12-24 |
For run UNIT-tests:
make test
Hint: Cover only repository with
sqlmock
and service layer withgomock