feign(负载)

也是做负载均衡的组件
pom.xml



    4.0.0
    
        org.springframework.boot
        spring-boot-starter-parent
        2.3.1.RELEASE
         
    
    com.com
    feign
    0.0.1-SNAPSHOT
    feign
    Demo project for Spring Boot

    
        1.8
        Hoxton.SR5
    

    
        
            org.springframework.cloud
            spring-cloud-starter-netflix-eureka-server
        
        
            org.springframework.cloud
            spring-cloud-starter-openfeign
        

        
            org.springframework.boot
            spring-boot-starter-test
            test
            
                
                    org.junit.vintage
                    junit-vintage-engine
                
            
        
    

    
        
            
                org.springframework.cloud
                spring-cloud-dependencies
                ${spring-cloud.version}
                pom
                import
            
        
    

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



yml

spring:
  application:
    name: feign
server:
  port: 8789
eureka:
  client:
    service-url:
      defaultZone: http://127.0.0.1:8081/eureka/

FeignApplication

@SpringBootApplication
@EnableFeignClients
@EnableDiscoveryClient
public class FeignApplication {

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

}
image.png

FeignService

@FeignClient(value = "client")
public interface FeignService {
    @RequestMapping(value = "hi",method = RequestMethod.GET)
    String sayHi(@RequestParam(value = "message") String message);
}

FeignController

@RestController
public class FeignController {
    @Autowired
    private FeignService feignService;
    @RequestMapping(value = "hi",method = RequestMethod.GET)
    public String sayHi(String message){
        System.out.println(message);
        return feignService.sayHi(message);
    }
}

你可能感兴趣的:(feign(负载))