欧美一级特黄大片做受成人-亚洲成人一区二区电影-激情熟女一区二区三区-日韩专区欧美专区国产专区

java怎么配置中心服務化和高可用-創(chuàng)新互聯(lián)

這篇文章主要介紹“java怎么配置中心服務化和高可用”的相關知識,小編通過實際案例向大家展示操作過程,操作方法簡單快捷,實用性強,希望這篇“java怎么配置中心服務化和高可用”文章能幫助大家解決問題。

創(chuàng)新互聯(lián)公司客戶idc服務中心,提供德陽服務器托管、成都服務器、成都主機托管、成都雙線服務器等業(yè)務的一站式服務。通過各地的服務中心,我們向成都用戶提供優(yōu)質廉價的產(chǎn)品以及開放、透明、穩(wěn)定、高性價比的服務,資深網(wǎng)絡工程師在機房提供7*24小時標準級技術保障。

客戶端和服務端的耦合性太高,如果server端要做集群,客戶端只能通過原始的方式來路由,server端改變IP地址的時候,客戶端也需要修改配置,不符合springcloud服務治理的理念。springcloud提供了這樣的解決方案,我們只需要將server端當做一個服務注冊到eureka中,client端去eureka中去獲取配置中心server端的服務既可。

server端改造

1、添加依賴

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

需要多引入spring-cloud-starter-eureka包,來添加對eureka的支持。

2、配置文件

server:
server:
  port: 8001
spring:
  application:
    name: spring-cloud-config-server
  cloud:
    config:
      server:
        git:
          uri: https://github.com/ityouknow/spring-cloud-starter/     # 配置git倉庫的地址
          search-paths: config-repo                             # git倉庫地址下的相對地址,可以配置多個,用,分割。
          username: username                                        # git倉庫的賬號
          password: password                                    # git倉庫的密碼
eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8000/eureka/   ## 注冊中心eurka地址

增加了eureka注冊中心的配置

3、啟動類

啟動類添加@EnableDiscoveryClient激活對配置中心的支持

@EnableDiscoveryClient
@EnableConfigServer
@SpringBootApplication
public class ConfigServerApplication {
 
	public static void main(String[] args) {
		SpringApplication.run(ConfigServerApplication.class, args);
	}
}

這樣server端的改造就完成了。先啟動eureka注冊中心,在啟動server端,在瀏覽器中訪問:http://localhost:8000/就會看到server端已經(jīng)注冊了到注冊中心了。

java怎么配置中心服務化和高可用

按照上篇的測試步驟對server端進行測試服務正常。

客戶端改造

1、添加依賴

<dependencies>
	<dependency>
		<groupId>org.springframework.cloud</groupId>
		<artifactId>spring-cloud-starter-config</artifactId>
	</dependency>
	<dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-web</artifactId>
	</dependency>
	<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>

需要多引入spring-cloud-starter-eureka包,來添加對eureka的支持。

2、配置文件

spring.application.name=spring-cloud-config-client
server.port=8002
 
spring.cloud.config.name=neo-config
spring.cloud.config.profile=dev
spring.cloud.config.label=master
spring.cloud.config.discovery.enabled=true
spring.cloud.config.discovery.serviceId=spring-cloud-config-server
 
eureka.client.serviceUrl.defaultZone=http://localhost:8000/eureka/

主要是去掉了spring.cloud.config.uri直接指向server端地址的配置,增加了最后的三個配置:

spring.cloud.config.discovery.enabled :開啟Config服務發(fā)現(xiàn)支持

spring.cloud.config.discovery.serviceId :指定server端的name,也就是server端spring.application.name的值

eureka.client.serviceUrl.defaultZone :指向配置中心的地址

這三個配置文件都需要放到bootstrap.properties的配置中

3、啟動類

啟動類添加@EnableDiscoveryClient激活對配置中心的支持

@EnableDiscoveryClient
@SpringBootApplication
public class ConfigClientApplication {
 
	public static void main(String[] args) {
		SpringApplication.run(ConfigClientApplication.class, args);
	}
}

啟動client端,在瀏覽器中訪問:http://localhost:8000/ 就會看到server端和client端都已經(jīng)注冊了到注冊中心了。

java怎么配置中心服務化和高可用

高可用

為了模擬生產(chǎn)集群環(huán)境,我們改動server端的端口為8003,再啟動一個server端來做服務的負載,提供高可用的server端支持。

java怎么配置中心服務化和高可用

如上圖就可發(fā)現(xiàn)會有兩個server端同時提供配置中心的服務,防止某一臺down掉之后影響整個系統(tǒng)的使用。

我們先單獨測試服務端,分別訪問:http://localhost:8001/neo-config/dev、http://localhost:8003/neo-config/dev返回信息:

{
    "name": "neo-config", 
    "profiles": [
        "dev"
    ], 
    "label": null, 
    "version": null, 
    "state": null, 
    "propertySources": [
        {
            "name": "https://github.com/ityouknow/spring-cloud-starter/config-repo/neo-config-dev.properties", 
            "source": {
                "neo.hello": "hello im dev"
            }
        }
    ]
}

說明兩個server端都正常讀取到了配置信息。

再次訪問:http://localhost:8002/hello,返回:hello im dev update。說明客戶端已經(jīng)讀取到了server端的內容,我們隨機停掉一臺server端的服務,再次訪問http://localhost:8002/hello,返回:hello im dev update,說明達到了高可用的目的。

關于“java怎么配置中心服務化和高可用”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關的知識,可以關注創(chuàng)新互聯(lián)-成都網(wǎng)站建設公司行業(yè)資訊頻道,小編每天都會為大家更新不同的知識點。

網(wǎng)頁名稱:java怎么配置中心服務化和高可用-創(chuàng)新互聯(lián)
文章來源:http://aaarwkj.com/article26/dpiscg.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站導航、網(wǎng)站策劃、ChatGPT、微信公眾號、用戶體驗、網(wǎng)站維護

廣告

聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)

h5響應式網(wǎng)站建設
日本人妻在线不卡视频| 国产av麻豆全部免费| 国产亚洲精品久久久久久| 在线观看不卡的黄色地址| 中文字幕三级电影天堂| 久久亚洲综合精品少妇| 日韩一二三区欧美四五区新| 先锋影音女同中文字幕| 天天躁日日躁夜夜躁夜夜| 久久综合午夜福利视频| 男女真人啪啪视频免费| 亚洲另类综合日韩一区| 亚洲中文字幕视频在看| 午夜亚洲欧美日韩在线| 日韩一二卡在线观看视频| 天堂av在线资源观看| 精品欧美日韩国产一区| 免费人成网站在线观看| 国产av剧情精品麻豆| 草草影院最新地址在线观看| 中文字幕成人在线电影| 日本在线一区二区视频麻豆| 国产一边打电话一边操| 尤物视频在线观看官网| 亚洲av二区三区成人| 国产三级精品在线免费 | 欧美亚洲尤物久久精品| 日韩一级黄色片在线播放| 国产午夜激情在线播放| 天堂在线av免费观看| 久久亚洲精品中文字幕| 最新日韩欧美一区二区| 久久婷婷激情亚洲综合色| 亚洲高清中文字幕专区| 久久碰国产一区二区三区| 亚洲熟女av一区少妇| 中文字幕人妻丝袜乱一区二区| 高清不卡一区二区在线观看| 国产精品欧美久久久久无| 高清免费在线自偷自拍| 亚洲情色精品国产一区|