https://github.com/ivangfr/spring-integration-examples
The goal of this project is to learn String Integration Framework For it, we will implement some Spring Boot applications and try to use the well known Enterprise Integration Patterns.
https://github.com/ivangfr/spring-integration-examples
docker enterprise-integration-patterns java mongodb spring-boot spring-data-mongodb spring-integration spring-integration-file spring-shell spring-web-mvc
Last synced: 3 months ago
JSON representation
The goal of this project is to learn String Integration Framework For it, we will implement some Spring Boot applications and try to use the well known Enterprise Integration Patterns.
- Host: GitHub
- URL: https://github.com/ivangfr/spring-integration-examples
- Owner: ivangfr
- Created: 2019-08-04T16:28:22.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2025-04-06T11:13:44.000Z (3 months ago)
- Last Synced: 2025-04-06T12:23:53.301Z (3 months ago)
- Topics: docker, enterprise-integration-patterns, java, mongodb, spring-boot, spring-data-mongodb, spring-integration, spring-integration-file, spring-shell, spring-web-mvc
- Language: Java
- Homepage:
- Size: 3.41 MB
- Stars: 4
- Watchers: 2
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
README
# spring-integration-examples
The goal of this project is to learn [`Spring Integration`](https://docs.spring.io/spring-integration/reference/). For it, we will implement some [`Spring Boot`](https://docs.spring.io/spring-boot/index.html) applications and try to use the well-known [`Enterprise Integration Patterns`](https://www.enterpriseintegrationpatterns.com/patterns/messaging/toc.html).
## Proof-of-Concepts & Articles
On [ivangfr.github.io](https://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.
## Project Architecture

## Applications
- ### calculator-api
`Spring Boot` Java 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 numbers `a` and `b`.
```text
POST /api/calculate -d { "a": number, "b": number, "operation": ["ADD" | "SUBTRACT" | "DIVIDE" | "MULTIPLY"] }
```
- ### file-service`Spring Boot` Java Web application that exposes an endpoint so that users can get information about a file. This service keeps looking at `shared/files` folder for created or modified files and save their content and info in [`MongoDB`](https://www.mongodb.com/).
```text
GET api/files/{filename}
```- ### spring-integration-shell
`Spring Boot Shell` Java application that has a couple of commands. One is to write some content to a file. Those files are stored in `shared/files` folder. Besides, there are some commands that uses `calculator-api` to compute the basic Math operations. There is also has a command that calls `file-service` in order to get information about a file. All the communication with `calculator-api` and `file-service` is over `HTTP`. Finally, there is a simple command called `greet`, so that you can display a greeting message on the screen depending on the time of the day.
## Prerequisites
- [`Java 21`](https://www.oracle.com/java/technologies/downloads/#java21) or higher;
- A containerization tool (e.g., [`Docker`](https://www.docker.com), [`Podman`](https://podman.io), etc.)## Start Environment
- Open a terminal and navigate to the `spring-integration-examples` root folder.
- Run the following command:
```bash
docker compose up -d
```## Running Applications with Maven
- **calculator-api**
In a terminal and inside the `spring-integration-examples` root folder run:
```bash
./mvnw clean spring-boot:run --projects calculator-api
```- **file-service**
Open a new terminal and inside the `spring-integration-examples` root folder run:
```bash
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-examples` root folder run:
```bash
SHARED_FILES_PATH=${PWD}/shared/files ./mvnw clean spring-boot:run --projects spring-integration-shell
```## Run applications as Docker containers
- ### Build Docker Images
- In a terminal, make sure you are in the `spring-integration-examples` root folder.
- Run the following script to build the Docker images:
```bash
./build-docker-images.sh
```- ### Environment Variables
- **calculator-api**
`None`
- **file-service**
| Environment Variable | Description |
|----------------------|---------------------------------------------------------------------|
| `MONGODB_HOST` | Specify host of the `MongoDB` database to use (default `localhost`) |
| `MONGODB_PORT` | Specify port of the `MongoDB` database to use (default `27017`) |- **spring-integration-shell**
| Environment Variable | Description |
|-----------------------|-------------------------------------------------------------------|
| `CALCULATOR_API_HOST` | Specify host of the `calculator-api` to use (default `localhost`) |
| `CALCULATOR_API_PORT` | Specify port of the `calculator-api` to use (default `9080`) |
| `FILE_SERVICE_HOST` | Specify host of the `file-service` to use (default `localhost`) |
| `FILE_SERVICE_PORT` | Specify port of the `file-service` to use (default `9081`) |- ### Start Docker Containers
- In a terminal, make sure you are inside the `spring-integration-examples` root folder.
- Run following command:
```bash
./start-services.sh && ./start-shell.sh
```## Playing around
- **calculator-api**
A sample of request to add two numbers:
```bash
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-shell` UI and a sample of execution:

- **file-service**
A sample of request to get information about a file:
```bash
curl -i http://localhost:9081/api/files/file.txt
```## Useful Commands
- **MongoDB**
Find all files:
```bash
docker exec -it mongodb mongosh filesdb
db.myFiles.find()
```
> Type `exit` to get out of `MongoDB shell`## Shutdown
- To stop `spring-integration-shell`, go to the terminal where it is running and type `exit`.
- To stop `calculator-api` and `file-service`:
- If you start them with `Maven`, go to the terminals were they are running and press `Ctrl+C`.
- If you start them as Docker containers, go to a terminal and, inside the `spring-integration-examples` root folder, run the following script:
```bash
./stop-services.sh
```
- To stop and remove `MongoDB` and docker compose network, go to a terminal and, inside the `spring-integration-examples` root folder, run the command below:
```bash
docker compose down -v
```## Cleanup
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:
```bash
./remove-docker-images.sh
```