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.
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:
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
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:
server:
port: 8761
eureka:
client:
registerWithEureka: false
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.
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.
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!