GithubHelp home page GithubHelp logo

spring-cloud's Introduction

Spring-Cloud

Eureka

    • Maven环境下:
    <!--https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-netflix-eureka-server-->
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
    </dependency>
  • 配置文件

    • SpringBoot环境下:

    key: value: 含义: 注: |:-: | :-: | :-: | :-:| |eureka:instance:hostname|127.0.0.1|服务注册中心IP地址| |eureka:client:registerWithEureka|false|是否向服务注册中心注册自己| |eureka:client:fetchRegistry|false|是否检索服务| |eureka:client:serviceUrl|defaultZone:
    http://${eureka.instance.hostname}:
    ${server.port}/eureka/|服务注册中心的配置内容,指定服务注册中心的位置|

  • 主要注解


    注解: 含义: 注: |:-: | :-: | :-:| |@EnableEurekaServer|启用Eureka服务端| |@EnableEurekaClient|如注册中心为Eureka,则推荐| |@EnableDiscoveryClient|注解中含有@EnableEurekaClient功能|

Feign

    • Maven环境下:(消费者中添加依赖)
    <!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-feign -->
      <dependency>
          <groupId>org.springframework.cloud</groupId>
          <artifactId>spring-cloud-starter-feign</artifactId>
          <version>1.4.6.RELEASE</version>
      </dependency>
    
  • 主要步骤


    步骤 Demo 注 |-|-|-| |创建一个名为UserFeignClient接口|@FeignClient(name="user-api")
    public interface UserFeignClient{
    @RequestMapping(value="/getUser")
    public String getUser(@RequestParam("id")int id);
    }|注:@FeignClient("")注解中name值为微服务项目在EurekaServer中注册名称。
    或与spring.application.name一致 |创建一个类提供方法,通过接口调用Eureka提供者的方法|@RestController
    public class UserController{
    @Autowired
    private UserFeignClient userFeignClient;
    @RequestMapping("/getUser")
    public String getUser(){
    return userFeignClient.getUser(2);
    }
    }| |修改启动类|@RestController
    @SpringBootApplication
    @EnableEurekaClient
    @EnableFeignClients
    public class UserserviceApplication{
    public static void main(String[] args){
    SpringApplication.run(UserserviceApplication.class,args);
    }
    }|


Hystrix

  • 主要步骤


    步骤 Demo 注 |-|-|-| |@FeignClient()加注解|@FeignClient(name="user-api",fallback=UserFeignClientFallBack.class)
    public interface UserFeignClient{
    @RequestMapping(value="/getUser")
    public String getUser(@RequestParam("id")int id);
    }| |创建容器处理类实现Feign接口|@Component
    public class UserFeignClientFallBack implements UserFeignClient{
    @Override
    public String getUser(int id){
    return "服务异常,请稍后重试";
    }
    }| |配置文件|feign:
    hystrix:
    enabled:true|


spring-cloud's People

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.