|
3 | 3 | ### Microservices Reference Application - What's For Dinner Appetizer Service
|
4 | 4 |
|
5 | 5 | *This project is part of the 'IBM Cloud Architecture - Microservices Reference Application for Netflix OSS' suite, available at
|
6 |
| -https://github.com/ibm-cloud-architecture/refarch-cloudnative-wfd*. There are three versions of the application, each available in their own branch, as documented below. |
| 6 | +https://github.com/ibm-cloud-architecture/refarch-cloudnative-netflix* |
7 | 7 |
|
8 |
| -- [Microprofile](../../tree/microprofile/) - leverages the Microprofile framework for the Java microservices framework of choice. |
9 |
| -- [Spring](../../tree/spring/) - leverages Spring Boot as the Java programming model of choice, with reliance on Kubernetes-based routing for microservices communication. |
10 |
| -- [Spring Cloud](../../tree/spring-cloud/) - leverages the Spring Cloud programming model (including Netflix OSS componentes) as the Java microservices framework of choice. |
| 8 | +#### Introduction |
| 9 | + |
| 10 | +This project is built to demonstrate how to build a Spring Boot application for use in a microservices-based architecture: |
| 11 | + - Leverage Spring Boot & Spring Cloud frameworks to build a microservices-based application. |
| 12 | + - Integrate with the [Netflix Eureka](https://github.com/Netflix/eureka) framework. |
| 13 | + - Deployment options for local, Cloud Foundry, or Docker Container-based runtimes (including [IBM Container Service](https://console.ng.bluemix.net/docs/containers/container_index.html) on [Bluemix](https://new-console.ng.bluemix.net/#overview)). |
| 14 | + |
| 15 | +Additionally, this microservice leverages robust resiliency capabilities, provided in this implementation by the Spring Cloud Config Server client libraries. The microservice will retry multiple times to contact the Config Server for the most up-to-date configuration data upon startup. Should the Config Server still be unavailable, after a configurable period of retries, the microservice will fail to start and can be diagnosed for additional connectivity problems or configured to be started with static built-in configuration data. |
| 16 | + |
| 17 | +For more information on Spring Cloud Config Server retry capabilities, you can reference the [Spring Cloud Config Server](https://cloud.spring.io/spring-cloud-config/spring-cloud-config.html#config-client-retry) documentation. Regardless of framework and tooling selection, resiliency capabilities, like this configurable retry logic, are critical in microservice-based applications. |
| 18 | + |
| 19 | +#### APIs in this application |
| 20 | +You can use cURL or Chrome POSTMAN to send get/post/put/delete requests to the application. |
| 21 | +- Get available options for Appetizers |
| 22 | +`http://<hostname>/appetizers` |
| 23 | + |
| 24 | +#### Configuration Options in this application |
| 25 | +These options can be set on the command-line, in a Docker Compose environment file, or any other way that [Spring Boot supports](https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html): |
| 26 | +- Disable Config Server retry logic, allowing startup without remote configuration data: |
| 27 | + `spring.cloud.config.failFast=false` |
| 28 | + |
| 29 | +#### Pre-requisite: |
| 30 | +- You need a Docker machine running on localhost to host container(s). [Click for instructions](https://docs.docker.com/machine/get-started/). |
| 31 | + |
| 32 | +#### Build the application |
| 33 | +1. Clone git repository. |
| 34 | + ``` |
| 35 | + git clone https://github.com/ibm-cloud-architecture/refarch-cloudnative-wfd-appetizer |
| 36 | + cd refarch-cloudnative-wfd-appetizer |
| 37 | + ``` |
| 38 | +
|
| 39 | +2. Build the application. A utility script is provided to easily build using either Gradle (default) or Maven. You can optionally specify the `-d` parameter to build the associated Docker image as well. The default Gradle build instructions use a Gradle wrapper requiring no further installation. The Maven build instructions require Maven to be installed locally. |
| 40 | +
|
| 41 | + 2.1 Build the application using Gradle: |
| 42 | + ``` |
| 43 | + ./build-microservice.sh [-d] |
| 44 | + ``` |
| 45 | +
|
| 46 | + 2.2 Build the application using Maven: |
| 47 | + ``` |
| 48 | + ./build-microservice.sh -m [-d] |
| 49 | + ``` |
| 50 | +
|
| 51 | +#### Run Appetizer Service on localhost |
| 52 | +In this section you will deploy the Spring Boot application to run on your localhost. |
| 53 | +
|
| 54 | +1. [Setup Eureka](https://github.com/ibm-cloud-architecture/refarch-cloudnative-netflix-eureka#run-the-application-component-locally) to run locally. |
| 55 | +
|
| 56 | +2. Run the application on localhost (assuming default Gradle build). If Eureka is not running locally, you will need to pass the location of the Eureka server as a command-line paramter. |
| 57 | + ``` |
| 58 | + java [-Deureka.client.serviceUrl.defaultZone=http://eureka-host:port/eureka/] -jar build/libs/wfd-appetizer-0.0.1-SNAPSHOT.jar |
| 59 | + ``` |
| 60 | +
|
| 61 | +3. Validate. |
| 62 | + ``` |
| 63 | + curl http://localhost:8082/appetizers |
| 64 | + {"order":1,"menu":["Hummus","Crab Cakes","Mozzerella Sticks"],"type":"appetizer"} |
| 65 | + ``` |
| 66 | +
|
| 67 | +#### Run Appetizer Service application on local Docker container |
| 68 | +In this section you will deploy the Spring Boot application to run in a local docker container. |
| 69 | +
|
| 70 | +1. Build service and container image: |
| 71 | + ``` |
| 72 | + ./build-microservice.sh -d |
| 73 | + ``` |
| 74 | +
|
| 75 | +2. If not done so already, [Setup Eureka](https://github.com/ibm-cloud-architecture/refarch-cloudnative-netflix-eureka#run-the-application-component-locally) to run locally. |
| 76 | +
|
| 77 | +3. Start the application in docker container. |
| 78 | + ``` |
| 79 | + docker run -d -p 8082:8082 --name wfd-appetizer --rm --env "eureka.client.serviceUrl.defaultZone=http://eureka-host:port/eureka/" wfd-appetizer |
| 80 | + ``` |
| 81 | +
|
| 82 | +4. Validate. |
| 83 | + ``` |
| 84 | + curl http://{docker-host}:8082/appetizers |
| 85 | + {"order":1,"menu":["Hummus","Crab Cakes","Mozzerella Sticks"],"type":"appetizer"} |
| 86 | + ``` |
| 87 | +
|
| 88 | +#### Deploy Appetizer Service to Cloud Foundry runtime, on IBM Bluemix |
| 89 | +
|
| 90 | +1. Log in to your Bluemix account. |
| 91 | + ``` |
| 92 | + cf login -a <bluemix-api-endpoint> -u <your-bluemix-user-id> |
| 93 | + ``` |
| 94 | +
|
| 95 | +2. Set target to use your Bluemix Org and Space. |
| 96 | + ``` |
| 97 | + cf target -o <your-bluemix-org> -s <your-bluemix-space> |
| 98 | + ``` |
| 99 | +
|
| 100 | +3. [Setup Eureka on Bluemix](https://github.com/ibm-cloud-architecture/refarch-cloudnative-netflix-eureka#run-the-application-component-on-bluemix). |
| 101 | +
|
| 102 | +4. Create a user-provided service for Eureka, so the services running in Cloud Foundry can bind to it: |
| 103 | +
|
| 104 | + ``` |
| 105 | + cf create-user-provided-service eureka-service-discovery -p "{\"uri\": \"http://{eureka-host}/eureka/\"}" |
| 106 | + ``` |
| 107 | +
|
| 108 | +5. Start the application in a Cloud Foundry runtime on IBM Bluemix. |
| 109 | +
|
| 110 | + The following commands push the service code to Bluemix and creates a Cloud Foundry application. It then sets the desired Spring Boot profile for the application to configure itself correctly, as well as binds the user-provided service with the Eureka endpoint information. Finally, it restages the application code to ensure it receives all the configuration changes and then starts the application. |
| 111 | +
|
| 112 | + _NOTE_: There is no need for a port in the Eureka parameter, as the Container Group running Eureka is listening on port 80 (the default HTTP port) and will forward to the necessary port of 8761 that Eureka is listening on. |
| 113 | +
|
| 114 | + ``` |
| 115 | + cf push -p build/libs/wfd-appetizer-0.0.1-SNAPSHOT.jar -d mybluemix.net -n wfd-appetizer-{your-bluemix-user-id} --no-start |
| 116 | +
|
| 117 | + cf set-env wfd-appetizer SPRING_PROFILES_ACTIVE cloud |
| 118 | +
|
| 119 | + cf bind-service wfd-appetizer eureka-service-discovery |
| 120 | +
|
| 121 | + cf restage wfd-appetizer |
| 122 | +
|
| 123 | + cf start wfd-appetizer |
| 124 | + ``` |
| 125 | +
|
| 126 | +6. Validate. |
| 127 | + ``` |
| 128 | + curl http://wfd-appetizer-{your-bluemix-user-id}.mybluemix.net/appetizers |
| 129 | + {"order":1,"menu":["Hummus","Crab Cakes","Mozzerella Sticks"],"type":"appetizer"} |
| 130 | + ``` |
| 131 | +
|
| 132 | +
|
| 133 | +#### Deploy Appetizer Service to Docker Container, on IBM Bluemix |
| 134 | +
|
| 135 | +1. Log in to your Bluemix account. |
| 136 | + ``` |
| 137 | + cf login -a <bluemix-api-endpoint> -u <your-bluemix-user-id> |
| 138 | + ``` |
| 139 | +
|
| 140 | +2. Set target to use your Bluemix Org and Space. |
| 141 | + ``` |
| 142 | + cf target -o <your-bluemix-org> -s <your-bluemix-space> |
| 143 | + ``` |
| 144 | +
|
| 145 | +3. Log in to IBM Containers plugin. |
| 146 | + ``` |
| 147 | + cf ic init |
| 148 | + ``` |
| 149 | +
|
| 150 | +4. Tag and push the local docker image to bluemix private registry. |
| 151 | + ``` |
| 152 | + docker tag wfd-appetizer registry.ng.bluemix.net/$(cf ic namespace get)/wfd-appetizer:latest |
| 153 | + docker push registry.ng.bluemix.net/$(cf ic namespace get)/wfd-appetizer:latest |
| 154 | + ``` |
| 155 | +
|
| 156 | +5. [Setup Eureka on Bluemix](https://github.com/ibm-cloud-architecture/refarch-cloudnative-netflix-eureka#run-the-application-component-on-bluemix). |
| 157 | +
|
| 158 | +6. Start the application in an IBM Bluemix Container. Replace `{eureka-host}` with the public route configured in the deployment of Eureka to Bluemix. |
| 159 | +
|
| 160 | + _NOTE_: There is no need for a port in the Eureka parameter, as the Container Group running Eureka is listening on port 80 (the default HTTP port) and will forward to the necessary port of 8761 that Eureka is listening on. |
| 161 | + ``` |
| 162 | + cf ic group create -p 8082 -m 256 --min 1 --auto --name wfd-appetizer-group -e "--env "eureka.client.serviceUrl.defaultZone=http://eureka-host/eureka/" -n wfd-appetizer-$(cf ic namespace get) -d mybluemix.net registry.ng.bluemix.net/$(cf ic namespace get)/wfd-appetizer:latest |
| 163 | + ``` |
| 164 | +
|
| 165 | +7. Validate. |
| 166 | + ``` |
| 167 | + curl http://wfd-appetizer-$(cf ic namespace get).mybluemix.net/appetizers |
| 168 | + {"order":1,"menu":["Hummus","Crab Cakes","Mozzerella Sticks"],"type":"appetizer"} |
| 169 | + ``` |
0 commit comments