第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

Spring-Cloud 快速入門(mén)——注冊(cè)中心與服務(wù)發(fā)現(xiàn)

標(biāo)簽:
Spring Cloud

从本章节开始,我们会接触Spring-Cloud的相关内容,SpringCloud分布式开发有五大利器,
服务发现——Netflix Eureka
客服端负载均衡——Netflix Ribbon
断路器——Netflix Hystrix
服务网关——Netflix Zuul
分布式配置——spring Cloud Config
这五大利器都是由Netflix公司开发的,并捐赠给了Apache开源组织。

先给大家看一下大概的微服务架构图,有一个整体的框架概念。

webp

我们会在接下去的章节中接触这些内容,本章节就开始讲注册中心与服务发现——Netflix Eureka

<strong>注册中心建立</strong>

1、pom.xml中引入 Eureka相关jar包

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-eureka-server</artifactId>
    </dependency></dependencies><dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>Brixton.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies></dependencyManagement>

2、启动类中引入注解,具体如下:

package com.cqf.chapter3;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;/**
 * 
 * @author qifu.chen
 * @version 1.0.0
 * @date May 16, 2017 3:11:16 PM
 */@EnableEurekaServer@SpringBootApplicationpublic class Application {    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

3、application.properties配置注册中心相关属性,这个文件的存放目录是src.main.resources

server.port=1111eureka.instance.hostname=localhost

eureka.client.register-with-eureka=falseeureka.client.fetch-registry=falseeureka.client.serviceUrl.defaultZone=http://localhost:${server.port}/eureka/

一个简单的注册中心就创建好了,需要注意,服务启动后,端口已经修改为1111,所以服务注册中心的访问地址是http://localhost:1111/

webp

具体详见demo <a >chapter3-eureka-server</a>

注册中心建好了,但是此时还没有任何的服务注册上来,下面就来讲解一下,怎么把服务注册到注册中心——服务发现。

<strong>服务发现</strong>

1、pom.xml文件引入相关jar包

<dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-eureka</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency></dependencies><dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>Brixton.RELEASE</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies></dependencyManagement>

2、编写启动类,这里和会中类的前面加入@EnableDiscoveryClient注解,服务启动时通过这个注解就能在注册中心发现此服务。

package com.cqf.chapter3;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cloud.client.discovery.EnableDiscoveryClient;/**
* 
* @author qifu.chen
* @version 1.0.0
* @date May 18, 2017 3:33:55 PM
*/@EnableDiscoveryClient@SpringBootApplicationclass Application {  public static void main(String[] args) {
      SpringApplication.run(Application.class, args);
  }
}

3、配置文件如下

spring.application.name=cqf-service

server.port=2222eureka.client.serviceUrl.defaultZone=http://localhost:1111/eureka/

这样,一个服务就提供出去了。需要注意,这里的服务启动端口是2222。
接下来,我们来启动一下这个服务,在注册中心就能看到这个服务,效果如下:

webp

具体详见demo <a >chapter3-cqf-service</a>



作者:cqf_
链接:https://www.jianshu.com/p/e6338b35d63e


點(diǎn)擊查看更多內(nèi)容
TA 點(diǎn)贊

若覺(jué)得本文不錯(cuò),就分享一下吧!

評(píng)論

作者其他優(yōu)質(zhì)文章

正在加載中
  • 推薦
  • 評(píng)論
  • 收藏
  • 共同學(xué)習(xí),寫(xiě)下你的評(píng)論
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說(shuō)多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開(kāi)微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊(cè)有機(jī)會(huì)得

100積分直接送

付費(fèi)專欄免費(fèi)學(xué)

大額優(yōu)惠券免費(fèi)領(lǐng)

立即參與 放棄機(jī)會(huì)
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)

舉報(bào)

0/150
提交
取消