From 5b21939e42325b1a889605e5693a49a2093a5851 Mon Sep 17 00:00:00 2001 From: jyunmitch Date: Mon, 12 Dec 2022 13:54:50 -0600 Subject: [PATCH 1/3] ENDOC-611 add sprint MS --- vuepress/docs/.vuepress/next.js | 4 + .../tutorials/create/ms/spring-boot-ms.md | 117 ++++++++++++++++++ 2 files changed, 121 insertions(+) create mode 100644 vuepress/docs/next/tutorials/create/ms/spring-boot-ms.md diff --git a/vuepress/docs/.vuepress/next.js b/vuepress/docs/.vuepress/next.js index fc5415f530..0ea4defc54 100644 --- a/vuepress/docs/.vuepress/next.js +++ b/vuepress/docs/.vuepress/next.js @@ -348,6 +348,10 @@ module.exports = { title: 'Generate Microservices and Micro Frontends', path: path + 'create/ms/generate-microservices-and-micro-frontends.md' }, + { + title: 'Create a Spring Boot Microservice', + path: path + 'create/ms/spring-boot-ms.md' + }, { title: 'Run Generated Components Locally', path: path + 'create/ms/run-local.md' diff --git a/vuepress/docs/next/tutorials/create/ms/spring-boot-ms.md b/vuepress/docs/next/tutorials/create/ms/spring-boot-ms.md new file mode 100644 index 0000000000..0d08d2e73a --- /dev/null +++ b/vuepress/docs/next/tutorials/create/ms/spring-boot-ms.md @@ -0,0 +1,117 @@ +--- +sidebarDepth: 2 +--- + +# Create a Spring Boot Microservice + +This tutorial uses the Spring Initializr to create a simple microservice to quicky generate an Entando Bundle project. + +## Prerequisites +- [A working instance of Entando](../../../docs/getting-started/) +- Verify dependencies with the [Entando CLI](../../../docs/getting-started/entando-cli.md#check-the-environment): `ent check-env develop` + +## Step 1: Initialize the Bundle with a Microservice + +1. Initialize a new bundle: +``` +ent bundle init e71-spring-project +``` +2. From the bundle project root directory, create a new microservice: +``` +cd e71-spring-project +ent bundle ms add spring-ms +``` + +## Step 2: Create the Microservice +1. At the Spring Initialyzr page, [start.spring.io](http://start.spring.io/), generate a project with the following configuration: +``` + Project=Maven + Language=Java + Spring Boot version=2.7.6 + Group=com.entando.example + Artifact=spring-ms + Name=spring-ms + Description=Demo project for Spring Boot + Package name=com.entando.example.spring-ms + Packaging=Jar + Java=11 + Dependencies= #under WEB: Spring Web + #under OPS: Spring Boot Actuator +``` + +2. Unzip the package and move the unzipped files and `src` directory to the `microservices/spring-ms/` directory. + +3. Create a new directory for the controller: +``` +mkdir microservices/spring-ms/src/main/java/com/entando/example/springms/controller +``` +4. In the controller directory, create `TemplateController.java` with the following content: +``` java +package com.entando.example.springms.controller; +import org.springframework.web.bind.annotation.*; +@RestController +public class TemplateController { + @CrossOrigin @GetMapping("/api/example") + public MyResponse getExample() { return new MyResponse("test Data"); } + public static class MyResponse{ + private final String payload; + public MyResponse(String payload) { this.payload = payload; } + public String getPayload() { return payload; } + } +} +``` + +5. To make the microservice compatible with Entando, add the following snippet to the `microservices/spring-ms/src/main/resources/application.properties` file: + +``` +server.port=8081 +management.endpoints.web.base-path=/api +``` +6. Run the microservice locally to test that it works: +``` +ent bundle run spring-ms +``` + +- In your browser, access [http://localhost:8081/api/example](http://localhost:8081/api/example) to see `{"payload":"test Data"}`. +- In your browser, access [http://localhost:8081/api/health](http://localhost:8081/api/health) to see `{"status":"UP"}`. +In local development, the run command can be used to modify the port to run multiple microservices, but in production, microservices must run on port 8081. + +7. Create `microservices/spring-ms/Dockerfile` so ent knows how to assemble the Docker image for the service: + +``` +FROM openjdk:11 +WORKDIR /app +COPY target/*.jar /app/app.jar +CMD ["java", "-jar", "app.jar"] +EXPOSE 8081 +``` +## Step 3: Build and Install the Bundle + +1. Optionally, add an image file in PNG or JPG format named thumbnail for the project. + +2. Package and install your bundle with the following commands: +``` +ent bundle pack +ent bundle publish +ent bundle deploy +ent bundle install +``` +3. To test the installed microservice, fetch your host name and microservice path with this command: +``` +ent kubectl describe ingress +``` +- The URL where your microservice can be accessed follows this pattern: +`YOUR-HOST-NAME/YOUR-BUNDLE-NAME/YOUR-MS-NAME/` + + With a local quickstart EntandoApp, the URL for this tutorial will look something like this: +`quickstart.192.168.64.34.nip.io/spring-ms-project-f5bb760b/spring-ms/` + +- Using this URL in your browser, go to +[http://quickstart.192.168.64.34.nip.io/e71-spring-project-f5bb760b/spring-ms/api/example/](http://quickstart.192.168.64.34.nip.io/e71-spring-project-f5bb760b/spring-ms/api/example/). It should return `{"payload":"test Data"}`. + + +**Next Steps** + +- Learn to connect micro frontends to microservices by [adding an API Claim](add-api-claim.md). +- Add a [configuration micro frontend](../mfe/widget-configuration.md) to your bundle project. + From cfc3a375c69105a59ceed31d81c76e36b483ed03 Mon Sep 17 00:00:00 2001 From: jyunmitch Date: Tue, 13 Dec 2022 14:38:16 -0600 Subject: [PATCH 2/3] ENDOC-611 review edits --- vuepress/docs/next/tutorials/create/ms/spring-boot-ms.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vuepress/docs/next/tutorials/create/ms/spring-boot-ms.md b/vuepress/docs/next/tutorials/create/ms/spring-boot-ms.md index 0d08d2e73a..559144bf59 100644 --- a/vuepress/docs/next/tutorials/create/ms/spring-boot-ms.md +++ b/vuepress/docs/next/tutorials/create/ms/spring-boot-ms.md @@ -4,7 +4,7 @@ sidebarDepth: 2 # Create a Spring Boot Microservice -This tutorial uses the Spring Initializr to create a simple microservice to quicky generate an Entando Bundle project. +This tutorial uses the Spring Initializr to create a simple microservice to quicky generate an Entando bundle project. ## Prerequisites - [A working instance of Entando](../../../docs/getting-started/) @@ -87,9 +87,9 @@ EXPOSE 8081 ``` ## Step 3: Build and Install the Bundle -1. Optionally, add an image file in PNG or JPG format named thumbnail for the project. +1. Optionally, add an image file in PNG or JPG format named `thumbnail` for the project. -2. Package and install your bundle with the following commands: +2. To install your bundle, execute the following commands: ``` ent bundle pack ent bundle publish @@ -103,7 +103,7 @@ ent kubectl describe ingress - The URL where your microservice can be accessed follows this pattern: `YOUR-HOST-NAME/YOUR-BUNDLE-NAME/YOUR-MS-NAME/` - With a local quickstart EntandoApp, the URL for this tutorial will look something like this: + In a quickstart environment, the URL for this tutorial will look something like this: `quickstart.192.168.64.34.nip.io/spring-ms-project-f5bb760b/spring-ms/` - Using this URL in your browser, go to From f1c24328f649a1e835651490e7900aa6a828e4cd Mon Sep 17 00:00:00 2001 From: jyunmitch Date: Thu, 15 Dec 2022 10:34:19 -0600 Subject: [PATCH 3/3] ENDOC-611 review updates --- .../tutorials/create/ms/spring-boot-ms.md | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/vuepress/docs/next/tutorials/create/ms/spring-boot-ms.md b/vuepress/docs/next/tutorials/create/ms/spring-boot-ms.md index 559144bf59..eeddd65b34 100644 --- a/vuepress/docs/next/tutorials/create/ms/spring-boot-ms.md +++ b/vuepress/docs/next/tutorials/create/ms/spring-boot-ms.md @@ -4,7 +4,7 @@ sidebarDepth: 2 # Create a Spring Boot Microservice -This tutorial uses the Spring Initializr to create a simple microservice to quicky generate an Entando bundle project. +This tutorial uses the Spring Initializr to create a simple microservice to quickly generate an Entando bundle project. ## Prerequisites - [A working instance of Entando](../../../docs/getting-started/) @@ -23,7 +23,7 @@ ent bundle ms add spring-ms ``` ## Step 2: Create the Microservice -1. At the Spring Initialyzr page, [start.spring.io](http://start.spring.io/), generate a project with the following configuration: +1. At the Spring Initialyzr page, [start.spring.io](http://start.spring.io/), create a project with the following configuration: ``` Project=Maven Language=Java @@ -35,9 +35,11 @@ ent bundle ms add spring-ms Package name=com.entando.example.spring-ms Packaging=Jar Java=11 - Dependencies= #under WEB: Spring Web - #under OPS: Spring Boot Actuator + Dependencies: + #under WEB: Spring Web + #under OPS: Spring Boot Actuator ``` + Click generate. 2. Unzip the package and move the unzipped files and `src` directory to the `microservices/spring-ms/` directory. @@ -45,7 +47,7 @@ ent bundle ms add spring-ms ``` mkdir microservices/spring-ms/src/main/java/com/entando/example/springms/controller ``` -4. In the controller directory, create `TemplateController.java` with the following content: +4. In the controller directory, create `TemplateController.java` with the following code: ``` java package com.entando.example.springms.controller; import org.springframework.web.bind.annotation.*; @@ -67,14 +69,14 @@ public class TemplateController { server.port=8081 management.endpoints.web.base-path=/api ``` -6. Run the microservice locally to test that it works: +6. Run the microservice from the bundle project root directory to test that it works: ``` ent bundle run spring-ms ``` - In your browser, access [http://localhost:8081/api/example](http://localhost:8081/api/example) to see `{"payload":"test Data"}`. -- In your browser, access [http://localhost:8081/api/health](http://localhost:8081/api/health) to see `{"status":"UP"}`. -In local development, the run command can be used to modify the port to run multiple microservices, but in production, microservices must run on port 8081. +- Then, access [http://localhost:8081/api/health](http://localhost:8081/api/health) to see `{"status":"UP"}`. +In local development, the run command can be used to modify the ports to run multiple microservices, but in production, microservices must run on port 8081. 7. Create `microservices/spring-ms/Dockerfile` so ent knows how to assemble the Docker image for the service: @@ -91,9 +93,15 @@ EXPOSE 8081 2. To install your bundle, execute the following commands: ``` -ent bundle pack +ent bundle pack +``` +``` ent bundle publish -ent bundle deploy +``` +``` +ent bundle deploy +``` +``` ent bundle install ``` 3. To test the installed microservice, fetch your host name and microservice path with this command: @@ -104,7 +112,7 @@ ent kubectl describe ingress `YOUR-HOST-NAME/YOUR-BUNDLE-NAME/YOUR-MS-NAME/` In a quickstart environment, the URL for this tutorial will look something like this: -`quickstart.192.168.64.34.nip.io/spring-ms-project-f5bb760b/spring-ms/` +`quickstart.192.168.64.34.nip.io/e71-spring-project-f5bb760b/spring-ms/` - Using this URL in your browser, go to [http://quickstart.192.168.64.34.nip.io/e71-spring-project-f5bb760b/spring-ms/api/example/](http://quickstart.192.168.64.34.nip.io/e71-spring-project-f5bb760b/spring-ms/api/example/). It should return `{"payload":"test Data"}`.