7

spring-cloud を使用してスプリング ブート アプリケーションを構築しましたが、統合テストに引き続き mockMvc を使用できるように、クライアント アプリケーション (これもマイクロサービス) 内で RestTemplate を使用したいと考えています。私は、呼び出しているサービス内のクライアント マイクロサービスと eureka クライアントで、デフォルトのリボン/eureka/hystrix クライアント セットアップを使用しています。これは機能しています(serviceIdsがrestTemplate内のサービスエンドポイントを識別するものであることを理解したら)。私の問題は、restTemplateの読み取りタイムアウトも接続タイムアウトも、デフォルトの300msのように見えるものから変更できないように見えることです。

通話の詳細:

`@Configuration
 @EnableAutoConfiguration
 @ComponentScan
 @EnableConfigurationProperties
 @EnableHystrix
 @EnableEurekaClient
public class Application { ... public static void main(String[] args) {} ... }

@Component
class EricComponentToDoHystrix {   // apparently this has to be a component for hystrix to work btw
    @Autowired
    RestTemplate restTemplate;
    ..
    @HystrixCommand(fallbackMethod="defaultRestTemplateCall")
    public void doRestTemplateCall() 
        ResponseEntity<String> result = restTemplate.getForEntity("http://someservice/doSomething", String.class);  // actually make a call
    ..
    }
}`

以下を含む application.properties を使用:

spring:
  cloud:
    client:
      serviceIds:
        - someservice

someservice:
  ribbon:
    #listOfServers: localhost:7080
    #NIWSServerListClassName: com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList

    # the eureka vipAddress of the target service (Disabled)
    DeploymentContextBasedVipAddresses: someservice

    # Interval to refresh the server list from the source
    ServerListRefreshInterval: 1000

    # Connect timeout used by Apache HttpClient.. apparently not by restTemplate 
    ConnectTimeout: 30000

    # Read timeout used by Apache HttpClient.. apparently not by restTemplate
    ReadTimeout: 30000

eureka:
  client:
    #Region where eureka is deployed -For AWS specify one of the AWS regions, for other datacenters specify a arbitrary string
    #indicating the region.This is normally specified as a -D option (eg) -Deureka.region=us-east-1
    region: default

    #For eureka clients running in eureka server, it needs to connect to servers in other zones
    preferSameZone: false

    us-east-1:
      availabilityZones: default

  instance:
    #Virtual host name by which the clients identifies this service
    virtualHostName: ${spring.application.name}
    appGroupName: ericGroup


# disable Ribbon's cicruit breaker and rely soley on Hystrix.
# this helps to avoid confusion.
# see https://github.com/Netflix/ribbon/issues/15
niws:
  loadbalancer:
    availabilityFilteringRule:
      filterCircuitTripped: false

restTemplate のデフォルトのタイムアウトを変更するために設定する必要があるプロパティを知っている人はいますか? ドキュメントはこの件に関して非常に軽く、コードはつい最近、restTemplate をリボン/eureka スプリング ブート デフォルトに対して使用することさえ許可したようです。おそらくこれはまだ構築されていません。

4

2 に答える 2

1

コメントできないのでお答えします。RestTemplate 統合は、RestClient や NFHttpClient ではなく、Ribbon LoadBalancer のみを使用します。

spring.cloud.client.serviceIds はもう必要ありません。ドキュメントにある場合は、削除します。

于 2014-10-09T19:23:00.117 に答える