1. 程式人生 > >SpringCloud-微服務-熔斷器Hystrix-使用時遇到的問題

SpringCloud-微服務-熔斷器Hystrix-使用時遇到的問題

使用時候遇到的問題:

對應的配置:

package com.nick.movie.service;

import com.nick.movie.service.impl.MicroCloudServiceHystrixImpl;
import com.nick.movie.config.MultipartSupportConfig;
import com.nick.movie.utils.ResponseResult;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;

/**
 * @version V1.0
 * @ClassName:MovieService
 * @author: hbj
 * @CreateDate:2018/8/27 19:34
 */
@FeignClient(value = "file-server", path = "/attachment/file" ,configuration = MultipartSupportConfig.class , fallback = MicroCloudServiceHystrixImpl.class)
public interface MicroCloudService {
    @RequestMapping(value = "/upload/single", produces = {MediaType.APPLICATION_JSON_UTF8_VALUE}, method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    ResponseResult uploadFileSingle(@RequestPart("file") MultipartFile file, @RequestParam("userId") Integer userId, @RequestParam("type") Integer type);
}
feign:
  hystrix:
    enabled: true
package com.nick.movie.service.impl;

import com.nick.movie.service.MicroCloudService;
import com.nick.movie.utils.ResponseResult;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;

/**
 * @version V1.0
 * @ClassName:ServiceHystrix
 * @author: hbj
 * @CreateDate:2018/8/31 17:39
 */
@Component
public class MicroCloudServiceHystrixImpl implements MicroCloudService {
    @Override
    public ResponseResult uploadFileSingle(MultipartFile file, Integer userId, Integer type) {
        return new ResponseResult().fail("呼叫檔案上傳服務失敗").code(500);
    }
}

問題出現原因:

 yml的配置已經過時,沒有起到作用

解決方法:重新正確配置熔斷器即可

hystrix:
  command:
    default:
      execution:
        isolation:
          thread:
            timeoutInMilliseconds: 100000
        timeout:
          enabled: false

ribbon:
  ReadTimeout: 5000
  ConnectTimeout: 3000
  maxAutoRetries: 1
  MaxAutoRetriesNextServer: 2
  OkToRetryOnAllOperations: true