日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

(十四)java版spring cloud+spring boot 社交电子商务平台-使用spring cloud Bus刷新配置...

發布時間:2023/12/20 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 (十四)java版spring cloud+spring boot 社交电子商务平台-使用spring cloud Bus刷新配置... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

電子商務平臺源碼請加企鵝求求:一零三八七七四六二六。我們使用spring cloud分布式微服務云架構做了b2b2c的電子商務系統,除了架構本身自帶的系統服務外,我們將b2b2c的業務服務進行了細粒度拆分,做成了不同的業務微服務。

當我們的業務系統越來越龐大復雜的時候,各種配置也會隨之增多。配置文件只要一修改,會對commonservice-config配置中心先停止服務,然后再重新啟動,最后使配置生效。

如果服務少,我們可以手動方式來啟動,但是對業務和系統的穩定性肯定有一定的影響。

如果是成百上千的服務都靠手動操作,我估計運維人員或技術人員會瘋掉的。

針對以上問題,commonservice-config服務端和業務微服務分別做了相關的配置,服務端負責將git(svn或本地文件系統)中存儲的配置文件進行配置化(我們使用的是本地配置方案,方便直接將配置文件更新到linux上),

業務微服務通過配置從服務端配置中心獲取相關配置,如果配置文件變動了,通過刷新業務微服務的方式,將最新的配置信息獲取。

spring cloud Bus通過一個輕量級消息代理連接分布式系統的節點。這可以用于廣播狀態更改(如配置更改)或其他管理指令。

接下來,我們就來實施通過spring cloud Bus方案,動態刷新服務端配置,具體步驟如下:

  • 業務微服務配置(以honghu-member-servcie會員服務為例):

    pom文件配置:

  • <span style="font-size: 16px;"> <dependency> <groupId>org.springframework.boot</groupId> <artifactId><span style="font-size: 16px;">spring-boot-starter-actuator</span></artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId><span style="font-size: 16px;">spring-cloud-starter-bus-amqp</span></artifactId> </dependency></span> 復制代碼

    yml文件配置:

    <span style="font-size: 16px;">server: port: 5012 spring: application: name: honghu-member-client profiles: active: dev,discoveryClient cloud: config: discovery: enabled: true service-id: commonservice-config-server <span style="font-size: 16px;"><strong>name: honghu-member profile: dev bus: trace: enabled: true #開啟消息跟蹤 </strong> <strong>rabbitmq: host: 192.168.1.254 port: 5672 username: honghu password: honghu</strong> </span> eureka: client: serviceUrl: defaultZone: http://honghu:123456@localhost:8761/eureka/ instance: prefer-ip-address: true logging: level: root: INFO org.springframework.security: INFO management: security: enabled: false security: basic: enabled: false</span> 復制代碼

    編寫一個測試類(MemberController.java),用來獲取配置項

    <span style="font-size: 16px;">package com.honghu.cloud.controller; import org.springframework.beans.factory.annotation.Value; import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; <strong>@RefreshScope</strong> @RestController public class MemberController { @Value("${profile}") private String profile; @GetMapping("/profile") public String getProfile() { return this.profile; } }</span> 復制代碼
  • 查看注冊中心,commonservice-config、honghu-member-service服務是否已經注冊成功
  • 訪問一下profile,獲取profile對應的配置信息(原配置):
  • 訪問http://localhost:7071/profile ==》 訪問結果:123456

  • 修改config配置中心的配置文件,將profile=123456修改為honghu123456
  • 再次訪問http://localhost:7071/profile ==》 訪問結果:123456

  • 使用spring cloud bus 刷新方案(使用post man測試工具進行測試)
  • http://localhost:7071/bus/refresh

    再次訪問http://localhost:7071/profile ==》 訪問結果:honghu123456

    到此,整個commonservice-config配置中心動態刷新方案整理完畢 。

    歡迎大家和我一起學習spring cloud構建微服務云架構,我這邊會將近期研發的spring cloud微服務云架構的搭建過程和精髓記錄下來,幫助更多有興趣研發spring cloud框架的朋友,大家來一起探討spring cloud架構的搭建過程及如何運用于企業項目。

    轉載于:https://juejin.im/post/5ceb53a4f265da1b9612e15f

    總結

    以上是生活随笔為你收集整理的(十四)java版spring cloud+spring boot 社交电子商务平台-使用spring cloud Bus刷新配置...的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。