This project consists of two services. One receives request via a Rest API and queues them in a RabbitMQ queue. The other consumes the queue, fetches the product information and sends an email with it.
There are two available ways to run the project. I'd recommend doing it with docker since it's easier. First you'll have to set up 2 .env files in each folder, I left you a python script that creates them.
Run:
python3 .\createEnvFiles.py host=rabbitMQ port=5672 username=guest password=guest email={email} email_password=
{app_password}
Note: The email provided will be the one sending the email, and the password needed to run this app is an application password which you can get here.
I'll leave you steps to run the project manually:
- Run rabbitMQ server locally
- Go to
./product-receiver
and runmvn clean package
and thenjava -jar target/product-0.0.1-SNAPSHOT.jar
- Then in another terminal go to
./product-request
and then run the same commands as 2.
Inside the root folder run the command: docker-compose up --build
The project only has one endpoint, to test it with curl:
curl -X POST http://localhost:8080/product/request -H "Content-Type: application/json" -d '{"email":"your_email",
"product_id": product_id}'
If you want to test it with powershell run:
$url = "http://localhost:8080/product/request"
$headers = @{
"Content-Type" = "application/json"
}
$body = @{
"email" = "[email protected]"
"product_id" = product_id
}
$jsonBody = $body | ConvertTo-Json
$response = Invoke-WebRequest -Uri $url -Method POST -Headers $headers -Body $jsonBody -ErrorAction Stop
Write-Output $response.Content
Note: I recommend using an email address that you can monitor.
- Maven
- Java 17
- RabbitMQ Server 3.13.4