①服务降级。
什么是服务降级:
整体资源快不够了,忍痛将某些服务先关掉,待渡过难关,再开启回来。
服务降级处理是在客户端(服务消费者、服务调用方)实现完成的,与服务端(服务提供者)没有关系。
服务熔断的坏处:容易方法膨胀。增加一个方法,就要增加一个fallbackMethod方法。而且出现高耦合现象。这时,我们需要解耦:
microservicecloud-provider-dept-hystrix-8001子工程的DeptController.java的全部内容是:
package com.lss.springcloud.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.lss.springcloud.entities.Dept;
import com.lss.springcloud.service.DeptService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
@RestController
public class DeptController {
@Autowired
private DeptService service;
@Autowired
private DiscoveryClient client;
@RequestMapping(value = "/dept/add", method = RequestMethod.POST)
public boolean add(@RequestBody Dept dept) {
return service.add(