flink从kafka读到写到kafka 笔记

博客提到在工作中,可在公司的flinksql platform平台上新增source table与sinktable,而非像代码那样注册。同时指出大数据量时,该平台不像flink能灵活设置并行度,公司似乎有small、middle和large三种规模,需工作时再确认。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 工作中可以不像下面代码一样注册source table 与sinktable 可以在公司的 flinksql platform 平台上

新增 source table 与sinktable 注意 大数据量时 不像flink一样可以灵活设置并行度 

公司好像分为三个规模 small middle and large 工作时再看看

package com.bigdata.flink.chap02;

import org.apache.flink.table.api.*;

import static org.apache.flink.table.api.Expressions.$;

public class FlinkTableAPIKafka2Kafka {
    public static void main(String[] args) {
        //1.创建TableEnvironment
        EnvironmentSettings settings = EnvironmentSettings
                .newInstance()
                .build();
        TableEnvironment tEnv = TableEnvironment.create(settings);

        //2.创建 source table
        Schema schema = Schema.newBuilder()
                .column("user", DataTypes.STRING())
                .column("url",DataTypes.STRING())
                .column("cTime",DataTypes.STRING())
                .build();
        tEnv.createTemporaryTable("sourceTable", TableDescriptor.forConnector("kafka")
                .schema(schema)
                .option("topic","clicklog_input")
                .option("properties.bootstrap.servers","hadoop1:9092")
                .option("properties.group.id","clicklog")
                .option("scan.startup.mode","earliest-offset")
                .option("format","json")
                .build()
        );

        //3.创建sink table
        tEnv.createTemporaryTable("sinkTable",TableDescriptor.forConnector("kafka")
                .schema(schema)
                .format("csv")
                .option("topic","clicklog_output")
                .option("properties.bootstrap.servers","hadoop1:9092")
                .build());

        //4.执行Table API 查询
        Table resultTable = tEnv.from("sourceTable").select($("user"),$("url"),$("cTime"));

        //5.输出
        resultTable.executeInsert("sinkTable");
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

我才是真的封不觉

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

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

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

打赏作者

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

抵扣说明:

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

余额充值