注冊中心Eureka
eureka的依賴?
<dependency> ? ? ? ? ? ?<groupId>org.springframework.cloud</groupId> ? ? ? ? ? ?<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> ? ? ? ?</dependency> ?
eureka的配置文件
spring: application: ? name: eureka-server server: port: 8001 eureka: client: ? service-url: ? ? defaultZone: http://localhost:8001/eureka/ ? fetch-registry: false ? ? #禁止當前項目寫入eureka服務中 ? register-with-eureka: false server: ? enable-self-preservation: false ?#關閉自我保護機制 ? eviction-interval-timer-in-ms: 4000 #剔除時間
register-with-eureka: false false表示不向注冊中心注冊自己
fetch-registry: false false表示自己就是注冊中心,不需要從注冊中心獲取注冊列表信息
service-url 設置eureka server交互的地址查詢服務和注冊服務都需要用到這個地址(單機用)
主啟動類
@SpringBootApplication @EnableEurekaServer // 聲明當前springboot應用是一個eureka服務中心 public class EurekaApp { ? ?public static void main(String[] args) { ? ? ? ?SpringApplication.run(EurekaApp.class); ? } }
搭建生產(chǎn)者Provider
引入依賴
文章來源:http://www.zghlxwxcb.cn/news/detail-763676.html
?<dependencies> ? ? ? ?<dependency> ? ? ? ? ? ?<groupId>org.springframework.cloud</groupId> ? ? ? ? ? ?<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> ? ? ? ?</dependency> ? <!-- ? ? ? 在provider的pom文件中添加監(jiān)控依賴--> ? ? ? ?<dependency> ? ? ? ? ? ?<groupId>org.springframework.boot</groupId> ? ? ? ? ? ?<artifactId>spring-boot-starter-actuator</artifactId> ? ? ? ?</dependency> ? ?</dependencies>
server: port: 9070 spring: application: ? name: user-server eureka: client: ? service-url: ? ? defaultZone: http://localhost:8001/eureka/ instance: ? prefer-ip-address: true ? instance-id: ${spring.cloud.client.ip-address}:${server.port} #顯示注冊的ip和端口 ? lease-renewal-interval-in-seconds: 5 ? ?#心跳時間 ? lease-expiration-duration-in-seconds: 20 #續(xù)約時間 order-provider: ribbon: ? NFLoadBalancerRuleClassName: com.netflix.loadbalancer.RandomRule management: ? #hystrix的數(shù)據(jù)流文件,存儲監(jiān)控數(shù)據(jù) endpoints: ? web: ? ? exposure: ? ? ? include: hystrix.stream
主啟動類
@SpringBootApplication @EnableEurekaClient // 或 @EnableDiscoveryClient public class ProviderApp { ? ?public static void main(String[] args) { ? ? ? ?SpringApplication.run(ProviderApp.class); ? } }
@EnableEurekaClient和@EnableDiscoveryClient區(qū)別 在使用Spring Cloud feign使用中在使用服務發(fā)現(xiàn)的時候提到了兩種注解: 一種為@EnableDiscoveryClient; 一種為@EnableEurekaClient,用法上基本一致文章來源地址http://www.zghlxwxcb.cn/news/detail-763676.html
到了這里,關于注冊中心Eureka的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!