├── .gitattributes ├── docker └── common │ └── docker-compose.yml ├── simpleservice ├── src │ └── main │ │ ├── docker │ │ ├── run.sh │ │ └── Dockerfile │ │ └── java │ │ └── com │ │ └── thoughtmechanix │ │ └── simpleservice │ │ └── Application.java └── pom.xml ├── .gitignore ├── pom.xml ├── .travis.yml └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | *.sh text eol=lf 2 | -------------------------------------------------------------------------------- /docker/common/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '2' 2 | services: 3 | simpleservice: 4 | image: johncarnell/tmx-simple-service:chapter1 5 | ports: 6 | - "8080:8080" 7 | -------------------------------------------------------------------------------- /simpleservice/src/main/docker/run.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | echo "********************************************************" 3 | echo "Starting simple-service " 4 | echo "********************************************************" 5 | java -jar /usr/local/simple-service/@project.build.finalName@.jar 6 | -------------------------------------------------------------------------------- /simpleservice/src/main/docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openjdk:8-jdk-alpine 2 | RUN apk update && apk upgrade && apk add netcat-openbsd 3 | RUN mkdir -p /usr/local/simple-service 4 | ADD @project.build.finalName@.jar /usr/local/simple-service/ 5 | ADD run.sh run.sh 6 | RUN chmod +x run.sh 7 | CMD ./run.sh 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Java class files 2 | *.class 3 | 4 | # Eclipse project files 5 | .classpath 6 | .project 7 | .settings/ 8 | 9 | # Intellij project files 10 | *.iml 11 | *.ipr 12 | *.iws 13 | .idea/ 14 | 15 | .DS_Store/ 16 | /target 17 | 18 | /target 19 | /target/ 20 | **/target/ 21 | 22 | .DS_Store 23 | -------------------------------------------------------------------------------- /simpleservice/src/main/java/com/thoughtmechanix/simpleservice/Application.java: -------------------------------------------------------------------------------- 1 | package com.thoughtmechanix.simpleservice; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | import org.springframework.web.bind.annotation.RequestMethod; 7 | import org.springframework.web.bind.annotation.RestController; 8 | import org.springframework.web.bind.annotation.PathVariable; 9 | 10 | @SpringBootApplication 11 | @RestController 12 | @RequestMapping(value="hello") 13 | public class Application { 14 | 15 | public static void main(String[] args) { 16 | SpringApplication.run(Application.class, args); 17 | } 18 | 19 | @RequestMapping(value="/{firstName}/{lastName}",method = RequestMethod.GET) 20 | public String hello( @PathVariable("firstName") String firstName, 21 | @PathVariable("lastName") String lastName) { 22 | 23 | return String.format("{\"message\":\"Hello %s %s\"}", firstName, lastName); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | com.thoughtmechanix 6 | 0.0.1-SNAPSHOT 7 | tmx-parent-pom 8 | pom 9 | 10 | 11 | thoughtmechanix-parent-pom 12 | Parent Pom for the thoughtmechanix project 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 1.4.4.RELEASE 18 | 19 | 20 | simpleservice 21 | 22 | 23 | 24 | 25 | com.spotify 26 | docker-maven-plugin 27 | 0.4.10 28 | 29 | java 30 | example 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | cache: 3 | directories: 4 | - $HOME/.m2 5 | jdk: 6 | - oraclejdk8 7 | sudo: required 8 | services: 9 | - docker 10 | notifications: 11 | slack: teamcarnell:zhTADgjsb7yJ5RPEd7LPNFwI 12 | email: 13 | - carnell28@gmail.com 14 | on_success: always 15 | on_failure: always 16 | before_install: 17 | - sudo curl -k -o /usr/local/bin/ecs-cli https://s3.amazonaws.com/amazon-ecs-cli/ecs-cli-linux-amd64-latest 18 | - sudo chmod +x /usr/local/bin/ecs-cli 19 | env: 20 | global: 21 | - secure: da8h8K0dKEeVrk+3zO8r9GEv6LqK+23QKZBshsQjyhsu2AT9O6/6EWGbS5mG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w6bF6N7XmWRPRgy8dDwI4w0eOmLVoGRTAQ5xeUJn9eMsItfEkTUzTY5jJF2fW0T9ymyJDKvPzNuWT79fBQWbf0EtwCjx7mHMX/WtaXjPhmvn9SzOo6B9sL5O3onlaGNhZ3u51E7QW5yLOIr1SaVaDrQ1dBODUBL17TeQzwnWFdcIshRVMwb5aQs0AJxrcrs6ptQts6MIZcwJWAyjEj5r9GRfhThoHHKNy3QQ= 23 | matrix: 24 | - TMX_DOCKER_IMAGE=johncarnell/tmx-simple-service:chapter1 25 | script: 26 | - docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD 27 | - mvn clean package docker:build 28 | - docker push $TMX_DOCKER_IMAGE 29 | - ecs-cli --version 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Introduction 2 | Welcome to Spring Microservices in Action, Chapter 1. Chapter 1 is an introduction to the book. The only code used in this Chapter is a simple, "helloworld" style service that demonstrates how to build a simple microservice using Spring Boot. 3 | 4 | # Software needed 5 | 1. Apache Maven (http://maven.apache.org). I used version 3.3.9 of the Maven. I chose Maven because, while other build tools like Gradle are extremely popular, Maven is still the pre-dominate build tool in use in the Java ecosystem. All of the code examples in this book have been compiled with Java version 1.8. 6 | 2. Docker (http://docker.com). I built the code examples in this book using Docker V1.12 and above. I am taking advantage of the embedded DNS server in Docker that came out in release V1.11. New Docker releases are constantly coming out so it's release version you are using may change on a regular basis. 7 | 3. Git Client (http://git-scm.com). All of the source code for this book is stored in a GitHub repository. For the book, I used version 2.8.4 of the git client. 8 | 9 | # Building the Docker Images for Chapter 1 10 | To build the code examples for Chapter 1 as a docker image, open a command-line window change to the directory where you have downloaded the chapter 1 source code. 11 | 12 | Run the following maven command. This command will execute the [Spotify docker plugin](https://github.com/spotify/docker-maven-plugin) defined in the pom.xml file. 13 | 14 | **mvn clean package docker:build** 15 | 16 | If everything builds successfully you should see a message indicating that the build was successful. 17 | 18 | # Running the Application for Chapter 1 19 | 20 | Now we are going to use docker-compose to start the actual image. To start the docker image, 21 | change to the directory containing your chapter 1 source code. Issue the following docker-compose command: 22 | 23 | **docker-compose -f docker/common/docker-compose.yml up** 24 | 25 | If everything starts correctly you should see a bunch of spring boot information fly by on standard out. At this point all of the services needed for the chapter code examples will be running. 26 | -------------------------------------------------------------------------------- /simpleservice/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | com.thoughtmechanix 6 | simple-service 7 | 0.0.1-SNAPSHOT 8 | jar 9 | 10 | Simple Service 11 | Simple Service 12 | 13 | 14 | org.springframework.boot 15 | spring-boot-starter-parent 16 | 1.4.4.RELEASE 17 | 18 | 19 | 20 | 21 | org.springframework.boot 22 | spring-boot-starter-web 23 | 24 | 25 | 26 | 27 | UTF-8 28 | 1.8 29 | UTF-8 30 | com.thoughtmechanix.simpleservice.Application 31 | johncarnell/tmx-simple-service 32 | chapter1 33 | 34 | 35 | 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-maven-plugin 40 | 41 | 42 | maven-resources-plugin 43 | 44 | 45 | copy-resources 46 | 47 | validate 48 | 49 | copy-resources 50 | 51 | 52 | ${basedir}/target/dockerfile 53 | 54 | 55 | src/main/docker 56 | true 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | com.spotify 65 | docker-maven-plugin 66 | 0.4.10 67 | 68 | ${docker.image.name}:${docker.image.tag} 69 | ${basedir}/target/dockerfile 70 | 71 | 72 | / 73 | ${project.build.directory} 74 | ${project.build.finalName}.jar 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | --------------------------------------------------------------------------------