内射老阿姨1区2区3区4区_久久精品人人做人人爽电影蜜月_久久国产精品亚洲77777_99精品又大又爽又粗少妇毛片

SpringCloud分布式微服務(wù)云架構(gòu)第八篇:消息總線(SpringCloudBus)(Finchley版本)

Spring Cloud Bus 將分布式的節(jié)點(diǎn)用輕量的消息代理連接起來。它可以用于廣播配置文件的更改或者服務(wù)之間的通訊,

創(chuàng)新互聯(lián)公司專注于羅莊網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠(chéng)為您提供羅莊營(yíng)銷型網(wǎng)站建設(shè),羅莊網(wǎng)站制作、羅莊網(wǎng)頁設(shè)計(jì)、羅莊網(wǎng)站官網(wǎng)定制、小程序設(shè)計(jì)服務(wù),打造羅莊網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供羅莊網(wǎng)站排名全網(wǎng)營(yíng)銷落地服務(wù)。

也可以用于監(jiān)控。本文要講述的是用Spring Cloud Bus實(shí)現(xiàn)通知微服務(wù)架構(gòu)的配置文件的更改。

一、準(zhǔn)備工作

本文還是基于上一篇文章來實(shí)現(xiàn)。按照官方文檔,我們只需要在配置文件中配置 spring-cloud-starter-bus-amqp ;

了解springcloud架構(gòu)可以加求求:三五三六二四七二五九,這就是說我們需要裝rabbitMq,點(diǎn)擊rabbitmq下載。至于怎么

使用 rabbitmq,搜索引擎下。

二、改造config-client

在pom文件加上起步依賴spring-cloud-starter-bus-amqp,完整的配置文件如下:

<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-netflix-eureka-client</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-bus-amqp</artifactId>
		</dependency>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-actuator</artifactId>
		</dependency>

在配置文件application.properties中加上RabbitMq的配置,包括RabbitMq的地址、端口,用戶名、密碼。并需要加上spring.cloud.bus的三個(gè)配置,具體如下:

spring.rabbitmq.host=localhost
spring.rabbitmq.port=5672
spring.rabbitmq.username=guest
spring.rabbitmq.password=guest
spring.cloud.bus.enabled=true
spring.cloud.bus.trace.enabled=true
management.endpoints.web.exposure.include=bus-refresh

ConfigClientApplication啟動(dòng)類代碼如下:

@SpringBootApplication
@EnableEurekaClient
@EnableDiscoveryClient
@RestController
@RefreshScope
public class ConfigClientApplication {
	/**
	 * http://localhost:8881/actuator/bus-refresh
	 */
	public static void main(String[] args) {
		SpringApplication.run(ConfigClientApplication.class, args);
	}
	@Value("${foo}")
	String foo;
	@RequestMapping(value = "/hi")
	public String hi(){
		return foo;
	}
}

依次啟動(dòng)eureka-server、confg-cserver,啟動(dòng)兩個(gè)config-client,端口為:8881、8882。

訪問http://localhost:8881/hi 或者h(yuǎn)ttp://localhost:8882/hi 瀏覽器顯示:

foo version 3

這時(shí)我們?nèi)ゴa倉庫將foo的值改為“foo version 4”,即改變配置文件foo的值。如果是傳統(tǒng)的做法,需要重啟服務(wù),

才能達(dá)到配置文件的更新。此時(shí),我們只需要發(fā)送post請(qǐng)求: http://localhost:8881/actuator/bus-refresh,你會(huì)發(fā)現(xiàn)

config-client會(huì)重新讀取配置文件

SpringCloud分布式微服務(wù)云架構(gòu) 第八篇: 消息總線(Spring Cloud Bus)(Finchley版本)

重新讀取配置文件:

SpringCloud分布式微服務(wù)云架構(gòu) 第八篇: 消息總線(Spring Cloud Bus)(Finchley版本)

這時(shí)我們?cè)僭L問http://localhost:8881/hi 或者h(yuǎn)ttp://localhost:8882/hi 瀏覽器顯示:

foo version 4

另外,/actuator/bus-refresh接口可以指定服務(wù),即使用"destination"參數(shù),比如 “/actuator/bus-refresh?destination=customers:**” 即刷新服務(wù)名為customers的所有服務(wù)。

三、分析

此時(shí)的架構(gòu)圖:

SpringCloud分布式微服務(wù)云架構(gòu) 第八篇: 消息總線(Spring Cloud Bus)(Finchley版本)

當(dāng)git文件更改的時(shí)候,通過pc端用post 向端口為8882的config-client發(fā)送請(qǐng)求/bus/refresh/;此時(shí)8882端口會(huì)發(fā)送一個(gè)消息,由消息總線向其他服務(wù)傳遞,從而使整個(gè)微服務(wù)集群都達(dá)到更新配置文件。

網(wǎng)站名稱:SpringCloud分布式微服務(wù)云架構(gòu)第八篇:消息總線(SpringCloudBus)(Finchley版本)
網(wǎng)站路徑:http://www.rwnh.cn/article6/jgpcog.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站設(shè)計(jì)標(biāo)簽優(yōu)化、、App開發(fā)、小程序開發(fā)、企業(yè)建站

廣告

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

成都做網(wǎng)站
新干县| 永城市| 临湘市| 株洲县| 青阳县| 西华县| 北川| 华蓥市| 游戏| 达孜县| 建德市| 正蓝旗| 东海县| 泽库县| 刚察县| 喀什市| 邵东县| 龙川县| 玉山县| 正蓝旗| 桃源县| 石城县| 锡林郭勒盟| 赫章县| 青冈县| 株洲县| 阿坝县| 桃园市| 铜山县| 揭阳市| 宾阳县| 扬州市| 民乐县| 河津市| 伊宁市| 肃南| 林甸县| 滨海县| 沭阳县| 恭城| 田阳县|