Today, I wanted to get my hands dirty with Eureka, specifically trying to “mount” it, as they say. I’ve heard a lot about it and finally decided to give it a shot. Here’s how my little adventure went.

Eureka Mount for Beginners: Your Simple Step-by-Step Walkthrough

Getting Started

First things first, I needed to have a Spring Boot project. I already had a basic one lying around from a previous experiment, so I dusted that off. If you don’t have one, you can easily create one using Spring Initializr—just a simple project with the ‘Web’ dependency will do.

Next, I needed to add the Eureka Server dependency to my . I opened up the file and slapped this in:

  • Added the dependency to the *.

<dependency>

<groupId>*</groupId>

<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>

Eureka Mount for Beginners: Your Simple Step-by-Step Walkthrough

</dependency>

I refreshed my Maven project to make sure everything downloaded properly. You know how it is, sometimes these things take a minute to sync up.

Setting Things Up

With the dependency in place, I moved on to the main application class. I needed to tell Spring that this application is going to be a Eureka server. So, I added the @EnableEurekaServer annotation right above the class definition. It looked something like this:

@SpringBootApplication

@EnableEurekaServer

Eureka Mount for Beginners: Your Simple Step-by-Step Walkthrough

public class EurekaServerApplication {

public static void main(String[] args) {

*(*, args);

Super simple, right? Just one annotation and you’re basically telling Spring, “Hey, make this a Eureka server!”

Configuration Time

Now, for the configuration. I created an file in the src/main/resources directory. I prefer YAML over properties files; it just looks cleaner to me. Inside, I added some basic configurations:

Eureka Mount for Beginners: Your Simple Step-by-Step Walkthrough

server:

port: 8761

eureka:

client:

registerWithEureka: false

Eureka Mount for Beginners: Your Simple Step-by-Step Walkthrough

fetchRegistry: false

serviceUrl:

defaultZone: http://localhost:8761/eureka/

I set the server port to 8761, which is like the default go-to port for Eureka. Then, I told it not to register with itself (registerWithEureka: false and fetchRegistry: false) because, well, it’s the server, not a client.

Firing It Up

With all that set, I ran the application. I right-clicked on the main class and hit ‘Run’. Fingers crossed, I watched the console logs scroll by. After a few seconds, it looked like everything started up without any explosions.

Eureka Mount for Beginners: Your Simple Step-by-Step Walkthrough

I opened up my browser and went to localhost:8761. And there it was! The Eureka server dashboard, looking all official and ready to go. It showed that no instances were registered yet, which made sense since I hadn’t set up any clients.

The Client Side (Quick and Dirty)

I opened another on my Springboot projects.

I add the dependency in my another project.

<dependency>

Eureka Mount for Beginners: Your Simple Step-by-Step Walkthrough

<groupId>*</groupId>

<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>

</dependency>

I add @EnableDiscoveryClient.

@SpringBootApplication

Eureka Mount for Beginners: Your Simple Step-by-Step Walkthrough

@EnableDiscoveryClient

public class DiscoveryServerApplication {

public static void main(String[] args) {

*(*, args);

I config my *:

Eureka Mount for Beginners: Your Simple Step-by-Step Walkthrough

spring:

application:

name: discovery-server

eureka:

client:

Eureka Mount for Beginners: Your Simple Step-by-Step Walkthrough

serviceUrl:

defaultZone: http://localhost:8761/eureka/

I ran another project. I refreshed my browser and went to localhost:8761.I saw the name of the application registered on the Eureka Server.

Wrapping Up

And that was it! I had successfully “mounted” Eureka and even got a basic client registered. It wasn’t as scary as I thought it would be. There’s a lot more to explore with Eureka, like setting up multiple instances and configuring more advanced settings, but this was a good start.

It’s always fun to get these things running and see them working with your own eyes. Makes you feel like you’ve accomplished something, you know? Next, I might play around with some service discovery and see how that goes. But for now, I’m calling it a day!

Eureka Mount for Beginners: Your Simple Step-by-Step Walkthrough

LEAVE A REPLY

Please enter your comment!
Please enter your name here