Implementing a service registry client

Previously, we mentioned that a load balancer used to be used to offer high scalability by using more than one server as a backend. Eureka works in the same way, but the main benefit is that you won't need to add any configuration in the service registry when more instances of a server are provisioned. Instead, every instance should let Eureka know that it wants to be registered.

Registering a new service is quite simple. You just need to include the following dependency:

compile
('org.springframework.cloud:spring-cloud-starter-netflix-eureka-client')

The service application class should include an additional annotation that will be discovered, as follows:

@EnableDiscoveryClient
@SpringBootApplication
public class MoviesServiceApplication
{
public static void main(String[] args)
{
SpringApplication.run(MoviesServiceApplication.class, args);
}
}

To finish up, you will need to specify the Eureka server URI as part of the application.properties file, as shown in the following code:

# This name will appear in Eureka
spring.application.name=movies-service
eureka.client.serviceUrl.defaultZone=http://localhost:8901/eureka

After running this Spring Boot application, it will be automatically registered in Eureka. You can verify this by refreshing the Eureka web console. You will see that the service is registered, as shown in the following screenshot:

Registered instances in Eureka

Once the services are registered, you will want to consume them. One of the easiest ways to consume services is by using Netflix Ribbon.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.198.94