Monday, April 12, 2021

Multiple Instances, LoadBalancer, @LoadBalanced

@LoadBalanced

import org.springframework.cloud.client.loadbalancer.LoadBalanced;

Why We place @LoadBalanced on RestTemplate because RestTemplate is used to to fetch Server IP Address and port from Eureka Registry and its also used for Client side Load Balancing


@EnableEurekaClient
public class MovieCatalogServiceApplication {

    public static void main(String[] args) {
        SpringApplication.run(MovieCatalogServiceApplication.class, args);
    }

    @Bean
    @LoadBalanced
    public RestTemplate getRestTemplate() {
        return new RestTemplate();
    }
}
See , In , Image Below, How Multiple Instances are registered of same application
We achieved by running application in an executable Jar in separate port

java -Dserver.port=8084 -jar movie-info-service-0.0.1-SNAPSHOT.jar


No comments:

Post a Comment

Azure - Pipeline - Add Approver for Stage

https://learn.microsoft.com/en-us/azure/devops/pipelines/process/approvals?view=azure-devops&tabs=check-pass