2016년 7월 17일 일요일

Client loadbalancing with ribbon (1)

You can loadbalance the traffic from cleint side by using netflix ribbon.
First of all, you can build up the client server like below.

(1) Client server

- Structure












- pom.xml



    4.0.0

    org.blog.test
    client-project
    1.0-SNAPSHOT

    
        org.springframework.boot
        spring-boot-starter-parent
        1.3.6.RELEASE
         
    

    
        UTF-8
        1.8
    

    
        
            org.springframework.boot
            spring-boot-starter-web
        
        
            org.springframework.boot
            spring-boot-starter-actuator
            1.3.6.RELEASE
        

    

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    




- application.properties

server.port=8888
spring.application.name=load-client

- ClientApplication

package org.blog.test;

import com.sun.deploy.util.SessionState;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class ClientApplication {

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

    @RequestMapping("/server/info")
    public String gethello() {
        return "client-1";
    }
}


You can also set the second client server by just changing the server port as 9999.

댓글 없음 :

댓글 쓰기