項目需要用到微服務,需要部署,學習了一下,記錄一下配置的內容:
一:
首先需要一個consul中繼:
然後我們使用dos命令窗口打開,並且啓動它:
啓動命令如下
consul.exe agent -server -bootstrap -ui -client 0.0.0.0 -data-dir="D:\software\consul\data" -bind 127.0.0.1
二:
在服務端添加服務加入配置信息,我們將這個配置文件放在配置文件目錄:
以下爲配置信息:
spring:
application:
name: 服務名稱
cloud:
consul:
config:
#format: KEY-VALUE
format: YAML
enabled: true
prefix: configuration
defaultContext: ${spring.application.name}
#profileSeparator: '::'
watch:
enabled: true
delay: 1000
host: 127.0.0.1
#host: consul.test.svc.cluster.local
port: 8500
discovery:
enabled: true
register: true
prefer-ip-address: true
service-name: ${spring.application.name}
#hostname: 127.0.0.1
#healthCheckUrl: http://127.0.0.1:9113/actuator/health
health-check-path: /actuator/health
health-check-interval: 15s
當然還需要依賴:
客戶端配置:
.
spring:
application:
name: erpnew
cloud:
consul:
config:
#format: KEY-VALUE
format: YAML
enabled: true
prefix: configuration
defaultContext: ${spring.application.name}
#profileSeparator: '::'
watch:
enabled: true
delay: 1000
host: 127.0.0.1
#host: consul.test.svc.cluster.local
port: 8500
discovery:
enabled: true
register: true
prefer-ip-address: true
service-name: ${spring.application.name}
#hostname: 127.0.0.1
#healthCheckUrl: http://127.0.0.1:9113/actuator/health
health-check-path: /actuator/health
health-check-interval: 15s
三:
客戶端配置:啓動類配置
訪問微服務內部中的接口@FeignClient(name= 微服務名稱)
然後這樣的話,我們前端請求客戶端,客戶端就會把相應的責任分離,去請求服務端。然後服務端返回結果給客戶端,客戶端出來過後給前端。