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


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

    2.1 克隆代码

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

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

    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
    
    • 1
    • 2
    • 3
    • 启动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
    
    • 1

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

    _Start the Kafka broker service

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

    2.4 然后开始打包

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

    ./mvnw clean install
    
    • 1

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

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

    2.6 启动shell

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

    2.7 创建流

    使用shell终端

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

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

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

    2.8 列出所有的流

    使用shell方式

    dataflow:>stream list
    ╔═══════════╤═════════════════╤══════════╗
    ║Stream Name│Stream Definition│  Status  ║
    ╠═══════════╪═════════════════╪══════════╣
    ║ticktock   │time | log       │undeployed║
    ╚═══════════╧═════════════════╧══════════╝
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

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

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

    2.9 发布流

    使用shell方式

    dataflow:>stream deploy --name ticktock
    Deployed stream 'ticktock'
    
    • 1
    • 2

    使用http方式如下:

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

    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
    
    • 1
    • 2

    如果使用 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
    
    • 1
    • 2
    • 3

    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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    快速失败
    在某些情况下,如果服务无法连接到配置服务器,则可能希望服务启动失败。 如果这是所需的行为,请设置引导配置属性 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`
    
    • 1

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

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

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

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

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

  • 相关阅读:
    在Linux上开启文件服务,需要安装并配置Samba
    中 秋 之 夜
    一键使用Mybatis-X生成逆向工程
    【集训DAY5】选数字【数学】
    Apache DolphinScheduler新一代分布式工作流任务调度平台实战
    Java内存模型介绍
    ES、kibana、JavaClient详细安装及操作
    FPGA底层资源综述
    ubuntu安装docker及 kubectl
    Docker Networking
  • 原文地址:https://blog.csdn.net/songjunyan/article/details/125471279