2016-08-12 5 views
0

Feign 스레드의 인스턴스가 안전합니까 ...? 이 문제를 지원하는 문서를 찾을 수 없습니다. 밖에서 다른 사람이 그렇게 생각합니까?Feign threadsafe ...가 맞습니까?

다음

표준 예 척하기위한 GitHub의의의 repo에 게시 ...

interface GitHub { 
    @RequestLine("GET /repos/{owner}/{repo}/contributors") 
    List<Contributor> contributors(@Param("owner") String owner, @Param("repo") String repo); 
} 

static class Contributor { 
    String login; 
    int contributions; 
} 

public static void main(String... args) { 
    GitHub github = Feign.builder() 
         .decoder(new GsonDecoder()) 
         .target(GitHub.class, "https://api.github.com"); 

    // Fetch and print a list of the contributors to this library. 
    List<Contributor> contributors = github.contributors("netflix", "feign"); 
    for (Contributor contributor : contributors) { 
    System.out.println(contributor.login + " (" + contributor.contributions + ")"); 
    } 
} 

내가 다음으로 변경해야 ...는 스레드 안전인가 ...?

interface GitHub { 
    @RequestLine("GET /repos/{owner}/{repo}/contributors") 
    List<Contributor> contributors(@Param("owner") String owner, @Param("repo") String repo); 
} 

static class Contributor { 
    String login; 
    int contributions; 
} 

@Component 
public class GithubService { 

    GitHub github = null; 

    @PostConstruct 
    public void postConstruct() { 
    github = Feign.builder() 
       .decoder(new GsonDecoder()) 
       .target(GitHub.class, "https://api.github.com"); 
    } 

    public void callMeForEveryRequest() { 
    github.contributors... // Is this thread-safe...? 
    } 
} 

위의 예제에서는 ... 나는 싱글 톤을 강조하기 위해 스프링 기반 구성 요소를 사용했습니다. 미리 감사드립니다 ...

답변

1

This 논의는 스레드 안전하다는 것을 시사하는 것 같다. (비효율적 인 새로운 객체를 만드는 것에 대한 이야기) 소스를 살펴보면 안전하지 못한 상태는없는 것처럼 보입니다. 이것은 저지 타겟을 모델로 한 것으로 예상됩니다. 그러나 안전하지 않은 방법으로 사용하기 전에 Feign 개발자로부터 확인을 받거나 자체 테스트를하고 검토해야합니다.

1

나는 또한보고 있었지만, 불행히도 아무것도 발견하지 못했습니다. 유일한 표시는 Spring 구성에서 제공됩니다. 빌더는 범위 프로토 타입의 bean으로 정의되므로 스레드로부터 안전하지 않아야합니다.

@Configuration 
public class FooConfiguration { 
    @Bean 
    @Scope("prototype") 
    public Feign.Builder feignBuilder() { 
     return Feign.builder(); 
    } 
} 

참조 : http://projects.spring.io/spring-cloud/spring-cloud.html#spring-cloud-feign-hystrix

+0

빌더가 프로토 타입 인 것은 당연하다고 생각하십니까? 빌더의 목표는 속성을 비 원자 적으로 설정하여 새로운 불변 ​​객체를 만드는 것입니다. 빌드되는 객체는 불변, 최종 및 스레드 세이프 일 수 있습니다. – Seagull