[SpringCloudDataFlow v2.3.0源码系列]-2-从一个简单的例子出发

2-从一个简单的例子出发

2.1 克隆代码

当前主要说版本v2.3.0.RELEASE,代码加载方式:

  • 克隆代码
git clone git@github.com:spring-cloud/spring-cloud-dataflow.git
  • 切换分支
git checkout v2.3.0.RELEASE

2.2 查看源代码之前我们先看下启动方式:

Data Flow Server 通过委托给 Spring Cloud Skipper 来部署 Streams,并直接部署 Tasks。
Skipper 和 Data Flow 服务器都可以部署到本地机器、Cloud Foundry 和 Kubernetes。

  • 本地启动

    • 参考网址:https://dataflow.spring.io/docs/installation/local/
  • Cloud Foundry平台部署

    • 关于Cloud Foundr云原生平台可以参考网址:https://www.cloudfoundry.org/
    • 部署文档参考:https://dataflow.spring.io/docs/installation/cloudfoundry/
  • Kubernetes编排部署
    -参考网址:https://dataflow.spring.io/docs/installation/kubernetes/

本地版本的数据流服务器应该只用于 Stream 开发,但可以在生产环境中用于任务部署,作为 Spring Cloud Batch Admin Server 的替代品。

接下来我们在本地启动 Data Flow Server 和 Shell 来创建time | 日志流。

2.3 在创建流之前我们先来启动kafka

参考网址: https://kafka.apache.org/quickstart

  • 下载和解压kafka
  wget https://downloads.apache.org/kafka/3.0.0/kafka_2.13-3.0.0.tgz
  tar -xzf kafka_2.13-3.0.0.tgz
  cd kafka_2.13-3.0.0
  • 启动KAFKA环境
    注意:您的本地环境必须安装 Java 8+。

运行以下命令以按正确顺序启动所有服务:

Start the ZooKeeper service
Note: Soon, ZooKeeper will no longer be required by Apache Kafka
.

bin/zookeeper-server-start.sh config/zookeeper.properties

打开另一个终端会话并运行:

_Start the Kafka broker service

bin/kafka-server-start.sh config/server.properties

2.4 然后开始打包

!!!这里注意命令是mvnw不是mvnmvnw

./mvnw clean install

2.5 启动数据流服务器应用程序:

java -jar spring-cloud-dataflow-server/target/spring-cloud-dataflow-server-<version>.jar

2.6 启动shell

java -jar spring-cloud-dataflow-shell/target/spring-cloud-dataflow-shell-<version>.jar

2.7 创建流

使用shell终端

dataflow:>stream create --name ticktock --definition "time | log"
Created new stream 'ticktock'

也可以使用http请求来创建:

curl -X POST -d "name=ticktock&definition=time | log" http://localhost:9393/streams/definitions?deploy=false

2.8 列出所有的流

使用shell方式

dataflow:>stream list
╔═══════════╤═════════════════╤══════════╗
║Stream Name│Stream Definition│  Status  ║
╠═══════════╪═════════════════╪══════════╣
║ticktock   │time | log       │undeployed║
╚═══════════╧═════════════════╧══════════╝

使用http请求方式访问如下:

curl http://localhost:9393/streams/definitions

2.9 发布流

使用shell方式

dataflow:>stream deploy --name ticktock
Deployed stream 'ticktock'

使用http方式如下:

curl -X POST http://localhost:9393/streams/deployments/ticktock

2.10 启动日志

如果成功,您应该会在 Data Flow Server 控制台中看到类似于以下内容的输出:

...o.s.c.d.spi.local.LocalAppDeployer    : deploying app ticktock.log instance 0
Logs will be in /some/path/ticktock.log

如果使用 tail stdout_0.log 文件,您应该看到类似于以下内容的输出:

2016-04-26 15:10:18.320  INFO 59890 --- [pool-1-thread-1] log.sink    : 04/26/16 15:10:18
2016-04-26 15:10:19.322  INFO 59890 --- [pool-1-thread-1] log.sink    : 04/26/16 15:10:19
2016-04-26 15:10:20.322  INFO 59890 --- [pool-1-thread-1] log.sink    : 04/26/16 15:10:20

2.11 配置

配置
默认
要配置数据流服务器,您可以遵循此处的引导文档中指定的配置设置指南

注意:可以在此处找到包含默认值的 dataflow-server.yml

Spring Cloud 配置
Spring Cloud Data Flow Server 为用户提供了通过 spring-cloud-config 配置属性的能力。 从云配置中检索到的所有配置将优先于上面列举的 Boot 的默认值。 Spring Cloud Data Flow Server 将在 localhost:8888 处查找服务器,但是这可以通过将 spring.cloud.config.uri 属性设置为所需的 url 来覆盖。

云配置服务器配置
要在云配置服务器 configuration.yml 中为数据流服务器指定存储库,请使用 spring-cloud-dataflow-server 模式设置存储库配置文件。 例如:

spring:
  cloud:
     config:
       server:
         git:
           uri: https://github.com/myrepo/configurations
           repos:
            spring-cloud-dataflow-server:
              pattern: spring-cloud-dataflow-server
              uri: https://github.com/myrepo/configurations
              searchPaths: dataFlowServer

快速失败
在某些情况下,如果服务无法连接到配置服务器,则可能希望服务启动失败。 如果这是所需的行为,请设置引导配置属性 spring.cloud.config.failFast=true 并且客户端将因异常而停止。

笔记
如果数据流服务器无法连接到云配置服务器,将记录以下警告消息:

`WARN 42924 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Could not locate PropertySource: I/O error on GET request for "http://localhost:8888/spring-cloud-dataflow-server/default":Connection refused; nested exception is java.net.ConnectException: Connection refused`

要禁用云配置服务器,请将 spring.cloud.config.enabled 属性设置为 false。

Docker-Compose 集成测试
要运行 docker compose 集成,请启用 -Pfailsafe maven 配置文件。

您只能像这样运行集成测试:

./mvnw clean test-compile failsafe:integration-test -pl spring-cloud-dataflow-server -Pfailsafe

查看更多原文,技术咨询支持,可以扫描微信公众号进行回复咨询
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

宋小生的博客

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值