├── src └── main │ ├── resources │ ├── bootstrap.yml │ └── application.yml │ └── java │ └── eurekademo │ └── EurekaClient.java ├── .gitignore ├── Procfile ├── app.json ├── pom.xml └── README.md /src/main/resources/bootstrap.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: my-service -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | #* 3 | *# 4 | .#* 5 | .classpath 6 | .project 7 | .settings 8 | target/ 9 | .idea 10 | *.iml 11 | -------------------------------------------------------------------------------- /Procfile: -------------------------------------------------------------------------------- 1 | web: java $JAVA_OPTS -Dserver.port=$PORT -jar target/eureka-client-demo-0.0.1-SNAPSHOT.jar --spring.profiles.active=heroku 2 | -------------------------------------------------------------------------------- /src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | eureka: 2 | client: 3 | serviceUrl: 4 | defaultZone: ${EUREKA_URL:http://user:password@localhost:5000}/eureka/ 5 | security: 6 | user: 7 | password: ${eureka.password} 8 | 9 | --- 10 | spring: 11 | profiles: heroku 12 | eureka: 13 | instance: 14 | hostname: ${DOMAIN_NAME} 15 | nonSecurePort: 80 16 | password: ${USER_PASSWORD:password} -------------------------------------------------------------------------------- /app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Eureka Client", 3 | "description": "Eureka Client demo project.", 4 | "website": "https://github.com/kissaten/heroku-eureka-client-demo", 5 | "success_url": "/health", 6 | "env": { 7 | "EUREKA_URL": { 8 | "description": "URL of the Eureka Server in the form http://:@" 9 | }, 10 | "DOMAIN_NAME": { 11 | "description": "The domain name of this app. For example: .herokuapp.com" 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/eurekademo/EurekaClient.java: -------------------------------------------------------------------------------- 1 | package eurekademo; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.EnableAutoConfiguration; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | import org.springframework.context.annotation.Configuration; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | @Configuration 11 | @EnableAutoConfiguration 12 | @EnableEurekaClient 13 | @RestController 14 | public class EurekaClient { 15 | 16 | @RequestMapping("/") 17 | public String home() { 18 | return "This is a trivial service that demonstrates how a Eureka Client can register with a Eureka Server"; 19 | } 20 | 21 | public static void main(String[] args) { 22 | SpringApplication.run(EurekaClient.class, args); 23 | } 24 | } -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.heroku 7 | eureka-client-demo 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | Eureka Client 12 | Eureka Client demo project 13 | 14 | 15 | org.springframework.cloud 16 | spring-cloud-starter-parent 17 | Angel.SR6 18 | 19 | 20 | 21 | 22 | 23 | org.springframework.cloud 24 | spring-cloud-starter-eureka-server 25 | 26 | 27 | org.springframework.boot 28 | spring-boot-starter-security 29 | 30 | 31 | org.springframework.boot 32 | spring-boot-starter-actuator 33 | 34 | 35 | org.springframework.boot 36 | spring-boot-starter-test 37 | test 38 | 39 | 40 | 41 | 42 | UTF-8 43 | eurekademo.EurekaClient 44 | 1.7 45 | 46 | 47 | 48 | 49 | 50 | org.springframework.boot 51 | spring-boot-maven-plugin 52 | 53 | 54 | maven-deploy-plugin 55 | 56 | true 57 | 58 | 59 | 60 | com.heroku.sdk 61 | heroku-maven-plugin 62 | 0.3.4 63 | 64 | ${heroku.appName} 65 | false 66 | 67 | target/${project.build.finalName}-${project.version}.jar 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | spring-snapshots 77 | Spring Snapshots 78 | http://repo.spring.io/libs-snapshot-local 79 | 80 | true 81 | 82 | 83 | 84 | spring-milestones 85 | Spring Milestones 86 | http://repo.spring.io/libs-milestone-local 87 | 88 | false 89 | 90 | 91 | 92 | spring-releases 93 | Spring Releases 94 | http://repo.spring.io/libs-release-local 95 | 96 | false 97 | 98 | 99 | 100 | 101 | 102 | spring-snapshots 103 | Spring Snapshots 104 | http://repo.spring.io/libs-snapshot-local 105 | 106 | true 107 | 108 | 109 | 110 | spring-milestones 111 | Spring Milestones 112 | http://repo.spring.io/libs-milestone-local 113 | 114 | false 115 | 116 | 117 | 118 | 119 | 120 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Netflix OSS on Heroku Demo: Eureka Client 2 | 3 | This project demonstrates the use of a Netflix OSS with Spring Cloud on Heroku. 4 | It defines a trivial service and registers that service with a Eureka server. 5 | 6 | Before using this project, you must have a [Eureka Server](https://github.com/kissaten/heroku-eureka-server-demo) deployed. 7 | 8 | ## Quickstart 9 | 10 | [![Deploy to Heroku](https://www.herokucdn.com/deploy/button.png)](https://heroku.com/deploy) 11 | 12 | Once it's deployed, you will need to define `$EUREKA_URL` and `$DOMAIN_NAME` config variables as described below. 13 | 14 | ## Deployment 15 | 16 | If you have already deploy the Eureka Server to Heroku, then you should already have a Heroku account and 17 | toolbelt installed. 18 | 19 | Once the Eureka Server is running, clone this project (the client) and move into it's root directory. 20 | 21 | ``` 22 | $ git clone git@github.com:kissaten/heroku-eureka-client-demo.git 23 | $ cd heroku-eureka-demo/ 24 | ``` 25 | 26 | Then create a Heroku application for the client by running this command: 27 | 28 | ````sh-session 29 | $ heroku create 30 | Creating fast-beach-5250... done, stack is cedar-14 31 | https://fast-beach-5250.herokuapp.com/ | https://git.heroku.com/fast-beach-5250.git 32 | Git remote heroku added 33 | ``` 34 | 35 | Now create a configuration variable to set the URL of the Eureka server. 36 | Run this command, but substitute the URL for `` in the form `https://user:password@.herokuapp.com`: 37 | 38 | ``` 39 | $ heroku config:set EUREKA_URL= 40 | ``` 41 | 42 | Also create a configuration variable for the domain name of your service -- this is the domain name that can be used 43 | to consume your service. By default it will be `.herokuapp.com`. You can set it like this: 44 | 45 | ``` 46 | $ heroku config:set DOMAIN_NAME=".herokuapp.com" 47 | ``` 48 | 49 | You're ready to deploy. There are two methods you can choose from: Git deployment and 50 | Maven deployment. The former compiles the application remotely, while the latter 51 | uses locally compiled artifacts and pushes them to Heroku. 52 | 53 | ### Deploying with Git 54 | 55 | With you're application prepared (as describe above), simply run this command to 56 | deploy via Git: 57 | 58 | ```sh-session 59 | $ git push heroku master 60 | ``` 61 | 62 | Your code will be pushed to the remote Git repository, and the Maven process 63 | will execute on the Heroku servers. 64 | 65 | ### Deploying with Maven 66 | 67 | With you're application prepared, simply run this command to 68 | deploy (but replace `` with the name of the Heroku application you created): 69 | 70 | ```sh-session 71 | $ mvn -Dheroku.appName= heroku:deploy 72 | ... 73 | [INFO] ---> Packaging application... 74 | [INFO] - app: 75 | [INFO] - including: ./target/eureka-client-demo-0.0.1-SNAPSHOT.jar 76 | [INFO] - installing: OpenJDK 1.8 77 | [INFO] ---> Creating slug... 78 | [INFO] - file: ./target/heroku/slug.tgz 79 | [INFO] - size: 79MB 80 | [INFO] ---> Uploading slug... 81 | [INFO] - stack: cedar-14 82 | [INFO] - process types: [web] 83 | [INFO] ---> Releasing... 84 | [INFO] - version: 4 85 | [INFO] ------------------------------------------------------------------------ 86 | [INFO] BUILD SUCCESS 87 | [INFO] ------------------------------------------------------------------------ 88 | [INFO] Total time: 01:29 min 89 | [INFO] Finished at: 2015-02-14T11:38:11-06:00 90 | [INFO] Final Memory: 27M/579M 91 | [INFO] ------------------------------------------------------------------------ 92 | ``` 93 | 94 | ## Viewing Your Application 95 | 96 | When your chosen deployment method is finished, run this command to view 97 | your application: 98 | 99 | ``` 100 | $ heroku open 101 | ``` 102 | 103 | After about 30 seconds, you can check the service was registered with the Eureka server. Log into the server, and 104 | you'll see "MY-SERVICE" under the section titled "Instances currently registered with Eureka". 105 | 106 | ## Further Reading 107 | 108 | + [Spring Cloud Netflix documentation](http://projects.spring.io/spring-cloud/spring-cloud.html#_spring_cloud_netflix) 109 | + [Netflix Eureka](https://github.com/netflix/eureka) --------------------------------------------------------------------------------