Skip to content

Commit fda3e71

Browse files
committed
Working version
1 parent 2b72c3e commit fda3e71

17 files changed

+876
-4
lines changed

README.md

+163-4
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,167 @@
33
### Microservices Reference Application - What's For Dinner Appetizer Service
44

55
*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*
77

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+
```

build-microservice.sh

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
3+
IMAGE_NAME=wfd-appetizer
4+
MAVEN_BUILD_TARGET=target/wfd-appetizer-0.0.1-SNAPSHOT.jar
5+
GRADLE_BUILD_TARGET=build/libs/wfd-appetizer-0.0.1-SNAPSHOT.jar
6+
7+
while getopts "md" ARG; do
8+
case ${ARG} in
9+
m)
10+
USE_MAVEN='yes'
11+
;;
12+
d)
13+
DO_DOCKER='yes'
14+
;;
15+
esac
16+
done
17+
18+
if [[ ${USE_MAVEN} == 'yes' ]]; then
19+
mvn clean package
20+
if [[ ${DO_DOCKER} == 'yes' ]]; then
21+
cp ${MAVEN_BUILD_TARGET} docker/app.jar
22+
fi
23+
else
24+
./gradlew clean build
25+
if [[ ${DO_DOCKER} == 'yes' ]]; then
26+
cp ${GRADLE_BUILD_TARGET} docker/app.jar
27+
fi
28+
fi
29+
30+
if [[ ${DO_DOCKER} == 'yes' ]]; then
31+
cd docker/
32+
docker build -t ${IMAGE_NAME} .
33+
fi

build.gradle

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
buildscript {
2+
ext {
3+
springBootVersion = '1.4.0.RELEASE'
4+
}
5+
repositories {
6+
mavenCentral()
7+
}
8+
dependencies {
9+
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
10+
}
11+
}
12+
13+
apply plugin: 'java'
14+
apply plugin: 'eclipse'
15+
apply plugin: 'spring-boot'
16+
17+
jar {
18+
baseName = 'wfd-appetizer'
19+
version = '0.0.1-SNAPSHOT'
20+
}
21+
sourceCompatibility = 1.8
22+
targetCompatibility = 1.8
23+
24+
repositories {
25+
mavenCentral()
26+
}
27+
28+
29+
dependencies {
30+
compile('org.springframework.retry:spring-retry')
31+
compile('org.springframework.boot:spring-boot-starter-aop')
32+
compile('org.springframework.cloud:spring-cloud-sleuth-zipkin')
33+
compile('org.springframework.cloud:spring-cloud-starter-sleuth')
34+
compile('org.springframework.cloud:spring-cloud-starter-config')
35+
compile('org.springframework.boot:spring-boot-starter-actuator')
36+
compile('org.springframework.cloud:spring-cloud-starter-eureka')
37+
compile('org.springframework.boot:spring-boot-starter-web')
38+
compile('io.springfox:springfox-swagger2:2.5.0')
39+
compile('io.springfox:springfox-swagger-ui:2.5.0')
40+
compile('io.swagger:swagger-annotations:1.5.10')
41+
testCompile('org.springframework.boot:spring-boot-starter-test')
42+
}
43+
44+
dependencyManagement {
45+
imports {
46+
mavenBom "org.springframework.cloud:spring-cloud-dependencies:Brixton.SR5"
47+
}
48+
}
49+
50+
51+
eclipse {
52+
classpath {
53+
containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
54+
containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8'
55+
}
56+
}

docker/Dockerfile

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM java:8
2+
# VOLUME /tmp
3+
ADD app.jar app.jar
4+
RUN bash -c 'touch /app.jar'
5+
6+
EXPOSE 8082
7+
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]

gradle/wrapper/gradle-wrapper.jar

52.3 KB
Binary file not shown.
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
zipStoreBase=GRADLE_USER_HOME
4+
zipStorePath=wrapper/dists
5+
distributionUrl=https\://services.gradle.org/distributions/gradle-2.13-bin.zip

0 commit comments

Comments
 (0)