top of page
Search
Writer's picturerussell colwell

Eureka!

Updated: Mar 23, 2020









Before we write a service to consume our task service we need to think about service discovery. Russ, why do we need service discovery? If you remember from our first post we are trying to build an application that we can move from cloud to cloud with ease. In order to do this we need to be able to call our application service with out having to change our source domain configurations every time. Having our own service discovery will help us accomplish this goal more efficiently. Don't worry spring and netflix have made this super easy for us to get up and running


 

Step 1: Create our eureka service project, just like we have done in the past




Step 2: Open up the application main and add the @EnableEurekaServer

Step 3: Add some configurations to your application.yml to your resources folder. You may need to create this your self or might ass an application.properties file from project generation. I just like to change it to application.yml because I find it easier to work with.


Step 4: Run your project and navigate to http://localhost:8761. Here you will your server running that is about it since we have not registered a service yet.


Step 5: No we need to get our task-service to register as an available service. Open up the task-service we created in the previous post. Navigate and open the build.gradle and add org.springframework.cloud:spring-cloud-starter-netflix-eureka-client & org.springframework.cloud:spring-cloud-starter-netflix-eureka-server to our dependencies. As well as the dependencyManagement & ext closures. Here is what your build.gradle should look like once complete.


Step 6: Now we need to add some configurations to our application.yml in the task service. We will add the service name so it shows up properly on the eureka page and some configurations to tell the client where to status.


Step 7: Build and run your task-service(gradlew bootRun) refresh your eureka server page and you should now see your service is registered.



Step 8: Don't forget to dockerize and build!

Dockerfile:

Then run your gradle build command and docker commands.


./gradlew jibDockerBuild --image=colwellcoding/cc-netflix

docker run -p 8761:8761 -t colwellcoding/cc-netflix


checkout your work one more time: http://localhost:8761.



We now have a functioning service registry we can use to register and retrieve service locations from. Once the cool wears off you might think to yourself, ok now how do I get the location of the task service from eureka to call from another service? Do not worry we are going to cover that... but now we re already up to 3 services, things get big fast. so before we do that for our next post I think we will cover how to add docker-compose to our project. this will allow us to build and run everything with some simple commands. Helping us in the long term with testing and organizational before it gets too big to handle.


I hope you enjoyed this! Let me know what you think.

 

Reference Links:

https://spring.io/

https://start.spring.io/

6 views0 comments

Recent Posts

See All

Comments


bottom of page