本文为您介绍Datastream作业开发POM依赖包、Datastream作业开发示例和Datastream Connector。

注意
  • 仅独享模式Blink3.2.2及以上版本支持Datastream功能。
  • 建议使用IntelliJ IDEA中的maven工程进行Datastream作业开发。
  • 实时计算独享模式不支持归档保存已停止(含暂停)的作业的运行日志。若需要查询已停止(含暂停)的作业运行日志,请将日志输出至用户自定义的SLS或OSS中。日志输出步骤参见自定义日志级别和下载路径

POM依赖包

请根据实际运行作业的Blink版本,自行添加开源版本所支持的POM依赖包。Blink3.4.0版本POM文件示例如下。
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.alibaba.blink</groupId>
    <artifactId>blink-datastreaming</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <scala.version>2.11.12</scala.version>
        <scala.binary.version>2.11</scala.binary.version>
        <blink.version>blink-3.4.0</blink.version>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.alibaba.blink</groupId>
            <artifactId>flink-streaming-java_${scala.binary.version}</artifactId>
            <version>${blink.version}</version>
            <scope>provided</scope>
        </dependency>

<!--        Add test framework-->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-library</artifactId>
            <version>2.11.12</version>
        </dependency>

<!--        Add logging framework-->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.7</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
            <scope>runtime</scope>
        </dependency>
    </dependencies>



    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.0</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <manifestEntries>
                                        <Main-Class>your main class</Main-Class>
                                        <X-Compile-Source-JDK>${maven.compiler.source}</X-Compile-Source-JDK>
                                        <X-Compile-Target-JDK>${maven.compiler.target}</X-Compile-Target-JDK>
                                    </manifestEntries>
                                </transformer>
                            </transformers>
                            <relocations combine.self="override">
                                <relocation>
                                    <pattern>XXX</pattern>
                                    <shadedPattern>shaded.XXX</shadedPattern>
                                </relocation>
                            </relocations>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
说明 如果您需要依赖Snapshot版本,可以自行添加Snapshot版本所支持的POM依赖包

作业示例

完整示例请参见读取DataHub数据示例

Connector列表

Blink 3.2版本新增如下Datastream Connector:
  • Kafka
  • Kafka(开源版本)
  • Hbase(开源版本)
  • JDBC
  • RDS SINK
  • Elesticsearch
  • MongoDB
  • Redis
说明 Datastream支持的部分Connector已完成开源,开源信息请参见alibaba-flink-connectors