The goal of this project is to learn Spring Integration. For it, we will implement some Spring Boot applications and try to use the well-known Enterprise Integration Patterns.
On ivangfr.github.io, I have compiled my Proof-of-Concepts (PoCs) and articles. You can easily search for the technology you are interested in using the filter. Who knows, perhaps I have already implemented a PoC or written an article about what you are looking for.
-
Spring BootJava Web application that exposes an endpoint so that users can submit the operation (addition, subtraction, division or multiplication) they want to perform over two decimal numbersaandb.POST /api/calculate -d { "a": number, "b": number, "operation": ["ADD" | "SUBTRACT" | "DIVIDE" | "MULTIPLY"] } -
Spring BootJava Web application that exposes an endpoint so that users can get information about a file. This service keeps looking atshared/filesfolder for created or modified files and save their content and info inMongoDB.GET api/files/{filename} -
Spring Boot ShellJava application that has a couple of commands. One is to write some content to a file. Those files are stored inshared/filesfolder. Besides, there are some commands that usescalculator-apito compute the basic Math operations. There is also has a command that callsfile-servicein order to get information about a file. All the communication withcalculator-apiandfile-serviceis overHTTP. Finally, there is a simple command calledgreet, so that you can display a greeting message on the screen depending on the time of the day.
- Open a terminal and navigate to the
spring-integration-examplesroot folder. - Run the following command:
docker compose up -d
-
calculator-api
In a terminal and inside the
spring-integration-examplesroot folder run:./mvnw clean spring-boot:run --projects calculator-api
-
file-service
Open a new terminal and inside the
spring-integration-examplesroot folder run:SHARED_FILES_PATH=${PWD}/shared/files ./mvnw clean spring-boot:run --projects file-service -
spring-integration-shell
Open a new terminal and inside the
spring-integration-examplesroot folder run:SHARED_FILES_PATH=${PWD}/shared/files ./mvnw clean spring-boot:run --projects spring-integration-shell
-
- In a terminal, make sure you are in the
spring-integration-examplesroot folder. - Run the following script to build the Docker images:
./build-docker-images.sh
- In a terminal, make sure you are in the
-
-
calculator-api
None -
file-service
Environment Variable Description MONGODB_HOSTSpecify host of the MongoDBdatabase to use (defaultlocalhost)MONGODB_PORTSpecify port of the MongoDBdatabase to use (default27017) -
spring-integration-shell
Environment Variable Description CALCULATOR_API_HOSTSpecify host of the calculator-apito use (defaultlocalhost)CALCULATOR_API_PORTSpecify port of the calculator-apito use (default9080)FILE_SERVICE_HOSTSpecify host of the file-serviceto use (defaultlocalhost)FILE_SERVICE_PORTSpecify port of the file-serviceto use (default9081)
-
-
- In a terminal, make sure you are inside the
spring-integration-examplesroot folder. - Run following command:
./start-services.sh && ./start-shell.sh
- In a terminal, make sure you are inside the
-
calculator-api
A sample of request to add two numbers:
curl -i -X POST http://localhost:9080/api/calculate \ -H 'Content-Type: application/json' \ -d '{"operation": "ADD", "a": 10, "b": 12}'
-
spring-integration-shell
The
spring-integration-shellUI and a sample of execution: -
file-service
A sample of request to get information about a file:
curl -i http://localhost:9081/api/files/file.txt
-
MongoDB
Find all files:
docker exec -it mongodb mongosh filesdb db.myFiles.find()
Type
exitto get out ofMongoDB shell
- To stop
spring-integration-shell, go to the terminal where it is running and typeexit. - To stop
calculator-apiandfile-service:- If you start them with
Maven, go to the terminals were they are running and pressCtrl+C. - If you start them as Docker containers, go to a terminal and, inside the
spring-integration-examplesroot folder, run the following script:./stop-services.sh
- If you start them with
- To stop and remove
MongoDBand docker compose network, go to a terminal and, inside thespring-integration-examplesroot folder, run the command below:docker compose down -v
To remove the Docker images created by this project, go to a terminal and, inside the spring-integration-examples root folder, run the following script:
./remove-docker-images.sh