在开发中运行 Spring Cloud 服务

Launcher CLI 可用于从命令行运行常见的服务,例如 Eureka、Config Server 等。要列出可用的服务,您可以执行 spring cloud --list;若要启动一组默认服务,只需执行 spring cloud。如需选择要部署的服务,只需在命令行中列出它们即可,例如:spring-doc.cadn.net.cn

$ spring cloud eureka configserver h2 kafka stubrunner zipkin

支持的部署组件摘要:spring-doc.cadn.net.cn

服务 姓名 地址 描述

eurekaspring-doc.cadn.net.cn

Eureka Serverspring-doc.cadn.net.cn

http://localhost:8761spring-doc.cadn.net.cn

Eureka 服务器用于服务注册与发现。所有其他服务默认会出现在其服务目录中。spring-doc.cadn.net.cn

配置服务器spring-doc.cadn.net.cn

配置服务器spring-doc.cadn.net.cn

http://localhost:8888spring-doc.cadn.net.cn

Spring Cloud Config Server 在 "native" 配置文件中运行,并从本地目录 ./launcher 提供配置信息。spring-doc.cadn.net.cn

h2spring-doc.cadn.net.cn

H2 数据库spring-doc.cadn.net.cn

http://localhost:9095 (控制台), jdbc:h2:tcp://localhost:9096/{data}spring-doc.cadn.net.cn

关系型数据库服务。连接时,请使用文件路径作为 {data}(例如 ./target/test)。请记住,您还可以添加 ;MODE=MYSQL;MODE=POSTGRESQL 以实现与其他服务器类型的兼容性连接。spring-doc.cadn.net.cn

Kafkaspring-doc.cadn.net.cn

Kafka Brokerspring-doc.cadn.net.cn

http://localhost:9091(actuator 端点),本地主机:9092spring-doc.cadn.net.cn

断路器仪表板spring-doc.cadn.net.cn

断路器仪表板spring-doc.cadn.net.cn

http://localhost:7979spring-doc.cadn.net.cn

任何声明了Hystrix断路器的Spring Cloud应用都会在端口/hystrix.stream发布指标。将该地址输入仪表板即可可视化所有指标spring-doc.cadn.net.cn

数据流spring-doc.cadn.net.cn

数据流服务器spring-doc.cadn.net.cn

http://localhost:9393spring-doc.cadn.net.cn

Spring Cloud Dataflow 服务器带有 UI 界面,地址为 /admin-ui。将 Dataflow 控制台连接到目标根路径。spring-doc.cadn.net.cn

zipkinspring-doc.cadn.net.cn

Zipkin Serverspring-doc.cadn.net.cn

http://localhost:9411spring-doc.cadn.net.cn

带有UI的Zipkin服务器,用于可视化跟踪。通过HTTP POST的JSON数据存储跨度数据到内存中。spring-doc.cadn.net.cn

stubrunnerspring-doc.cadn.net.cn

<!DOCTYPE html> <html> <head> <title>Spring框架中文网站</title> </head> <body> <h1>Spring框架</h1> <p>这是一个用于Java开发的Spring框架英文网站的中文翻译。</p> <footer>版权所有 © 2023</footer> </body> </html>spring-doc.cadn.net.cn

http://localhost:8750spring-doc.cadn.net.cn

Downloads WireMock stubs, starts WireMock and feeds the started servers with stored stubs. Pass stubrunner.ids to pass stub coordinates and then go to http://localhost:8750/stubs.spring-doc.cadn.net.cn

每个应用程序都可以使用本地 YAML 文件进行配置,文件名相同(在当前工作目录或名为“config”的子目录中的“0”)。例如,在“1”中,您可能要执行类似的操作来定位用于后端的本地 git 仓库:spring-doc.cadn.net.cn

configserver.yml
spring:
  profiles:
    active: git
  cloud:
    config:
      server:
        git:
          uri: file://${user.home}/dev/demo/config-repo

E.g. in Stub Runner app you could fetch stubs from your local .m2 in the following way.spring-doc.cadn.net.cn

stubrunner.yml
stubrunner:
  workOffline: true
  ids:
    - com.example:beer-api-producer:+:9876

添加额外的应用程序

更多应用可以添加到./config/cloud.yml(而不是./config.yml,因为这会替换默认值),例如通过spring-doc.cadn.net.cn

config/cloud.yml
spring:
  cloud:
    launcher:
      deployables:
        source:
          coordinates: maven://com.example:source:0.0.1-SNAPSHOT
          port: 7000
        sink:
          coordinates: maven://com.example:sink:0.0.1-SNAPSHOT
          port: 7001

当你列出app时,spring-doc.cadn.net.cn

$ spring cloud --list
source sink configserver dataflow eureka h2 hystrixdashboard kafka stubrunner zipkin

(请注意列表开头处的其他应用)。spring-doc.cadn.net.cn