Skip to content

Commit

Permalink
Update README, enable Spring Boot auto-reload and change APIs URL
Browse files Browse the repository at this point in the history
  • Loading branch information
aowss committed May 15, 2024
1 parent 52bbe0a commit e829d28
Show file tree
Hide file tree
Showing 11 changed files with 124 additions and 5 deletions.
50 changes: 47 additions & 3 deletions spring-boot/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,58 @@
# Spring Boot Samples

<!-- TOC -->
* [Spring Boot Samples](#spring-boot-samples)
* [Run Locally](#run-locally)
* [Run Camunda locally](#run-camunda-locally)
* [Add permissions to the `zeebe` application](#add-permissions-to-the-zeebe-application)
* [Run a mock API server](#run-a-mock-api-server)
* [Run the application](#run-the-application)
<!-- TOC -->

## Run Locally

### Run Camunda locally

Run Camunda locally as explained [here](../docker/README.md).

#### Add permissions to the `zeebe` application

The `zeebe` client is configured in `application-local.yaml` and used to access the Tasklist.

```yaml
zeebe:
client:
cloud:
client-id: zeebe

tasklist:
client-id: ${zeebe.client.cloud.client-id}
```
We therefore need to:
* log in to [Identity](http://localhost:8084),
* edit the `zeebe` application,
* and add Tasklist read/write permissions.

![](./docs/res/Tasklist-Permission.png)

### Run a mock API server

If the sample calls any external APIs, run [a mock API server](./mock-api/README.md) locally.

### Run the application

The [Spring Boot Maven Plugin](https://docs.spring.io/spring-boot/docs/current/maven-plugin/reference/htmlsingle/) is configured in this [`pom.xml`](./pom.xml) to use the `local` profile by default.

In each module, the `application-local.yaml` file is configured to run against a local deployment of Camunda.
The [`Camunda Platform 8` repository](https://github.com/camunda/camunda-platform) documents how to run a complete Camunda Platform 8 Self-Managed environment locally.
In each module, the `application-local.yaml` file is configured to run against a [local deployment of Camunda](#run-camunda-locally).

The following command will therefore run using that profile.

> `mvn spring-boot:run`

It is possible to run using another profile by setting the `spring-boot.run.profiles` property, e.g. `-Dspring-boot.run.profiles=dev`.
It is possible to run using another profile by setting the `spring-boot.run.profiles` property, e.g. `-Dspring-boot.run.profiles=dev`, as documented [here](https://docs.spring.io/spring-boot/docs/current/maven-plugin/reference/htmlsingle/#using.overriding-command-line).

The `APIS_HOST` environment variable contains the external APIs' host.
It is set to `localhost` by default to point to [the local mock API server](#run-a-mock-api-server).
The mock API server is assumed to run on port `9999`.
Binary file added spring-boot/docs/res/Tasklist-Permission.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions spring-boot/mock-api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Mock API Server

This is used to mock external APIs that might be used in the samples.

We use the [Wiremock Docker image](https://wiremock.org/docs/standalone/docker/).

As mentioned in the documentation, the server can be started as follows:

> `docker run -it --rm -p 9999:8080 -v $PWD:/home/wiremock --name mock-api-server wiremock/wiremock`
The mock server is configured to respond without error to the external API calls.

You can customize the responses by editing the files located in the [`__files`](./__files) and [`mappings`](./mappings) folders.

3 changes: 3 additions & 0 deletions spring-boot/mock-api/__files/dispatch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"orderId": "O-1234"
}
3 changes: 3 additions & 0 deletions spring-boot/mock-api/__files/invoice.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"orderId": "O-1234"
}
3 changes: 3 additions & 0 deletions spring-boot/mock-api/__files/notification.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"orderId": "O-1234"
}
3 changes: 3 additions & 0 deletions spring-boot/mock-api/__files/order.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"orderId": "O-1234"
}
44 changes: 44 additions & 0 deletions spring-boot/mock-api/mappings/cancellation.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"mappings": [
{
"request": {
"method": "POST",
"urlPath": "/order"
},
"response": {
"status": 201,
"bodyFileName": "order.json"
}
},
{
"request": {
"method": "POST",
"urlPath": "/invoice"
},
"response": {
"status": 201,
"bodyFileName": "invoice.json"
}
},
{
"request": {
"method": "POST",
"urlPath": "/notification"
},
"response": {
"status": 201,
"bodyFileName": "notification.json"
}
},
{
"request": {
"method": "POST",
"urlPath": "/dispatch"
},
"response": {
"status": 201,
"bodyFileName": "dispatch.json"
}
}
]
}
5 changes: 5 additions & 0 deletions spring-boot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
<version>${camunda.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ server:
port: 9000

api:
url: http://${ENV:prod}-rates:9999/exchangeRates
url: http://${APIS_HOST:localhost}-rates:9999/exchangeRates

# See https://github.com/camunda/connectors/tree/main/connector-runtime/spring-boot-starter-camunda-connectors
camunda:
Expand Down
2 changes: 1 addition & 1 deletion spring-boot/task/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ server:
port: 9000

api:
url: http://${ENV:prod}-rates:9999/exchangeRates
url: http://${APIS_HOST:localhost}-rates:9999/exchangeRates

camunda:
connector:
Expand Down

0 comments on commit e829d28

Please sign in to comment.