一:feign是springCloud跨服务调用的组件,feign底层也是一个基于http的封装
我现在创建两个服务,一个消费者,一个生产者:
pom:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
创建一个生产者:
server:
port: 8020
spring:
application:
name: producer
eureka:
client:
healthcheck:
enabled: true #健康检查
serviceUrl.defaultZone: http://localhost:8010/eureka/
instance:
instance-id: ${spring.cloud.client.ip-address}:${server.port}
prefer-ip-address: true
lease-expiration-duration-in-seconds: 10 # 发呆时间,即服务续约到期时间(缺省为90s)
lease-renewal-interval-in-seconds: 5 # 心跳时间,即服务续约间隔时间(缺省为30s)
metadata-map:
cluster: service
feign:
hystrix:
enabled: true
创建一个http接口:
package com.example.producer.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @Auther: gongyiyang
* @Date: 2018/10/22