栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

flink写入starrocks案例

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

flink写入starrocks案例

StarRocks Connector

		
            mysql
            mysql-connector-java
            8.0.20
        
        
            org.apache.flink
            flink-connector-jdbc_2.12
            1.13.5
        

        
            com.starrocks
            flink-connector-starrocks
            1.1.16_flink-1.13_2.12
        

StarRocksSinkExample

import com.starrocks.connector.flink.StarRocksSink;
import com.starrocks.connector.flink.table.StarRocksSinkOptions;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.table.api.DataTypes;
import org.apache.flink.table.api.TableSchema;

public class StarRocksSinkExample {

    static class Book {
        public Book(Long id, String title, String authors, Integer year) {
            this.id = id;
            this.title = title;
            this.authors = authors;
            this.year = year;
        }
        final Long id;
        final String title;
        final String authors;
        final Integer year;
    }

    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        env.fromElements(
                new Book(101L, "Stream Processing with Apache Flink", "Fabian Hueske, Vasiliki Kalavri", 2019),
                new Book(102L, "Streaming Systems", "Tyler Akidau, Slava Chernyak, Reuven Lax", 2018),
                new Book(103L, "Designing Data-Intensive Applications", "Martin Kleppmann", 2017),
                new Book(104L, "Kafka: The Definitive Guide", "Gwen Shapira, Neha Narkhede, Todd Palino", 2017)
        ).addSink(
                StarRocksSink.sink(
                        TableSchema.builder()
                                .field("id", DataTypes.BIGINT())
                                .field("title", DataTypes.VARCHAr(100))
                                .field("authors", DataTypes.VARCHAr(100))
                                .field("year", DataTypes.INT())
                                .build(),
                        StarRocksSinkOptions.builder()
                                .withProperty("connector","starrocks")
                                .withProperty("jdbc-url","jdbc:mysql://10.x.x.x:9030?characterEncoding=utf-8&useSSL=false")
                                .withProperty("load-url","10.x.x.x:8030;10.x.x.x:8030;10.x.x.x:8030")
                                .withProperty("username","root")
                                .withProperty("password","pass")
                                .withProperty("table-name","book")
                                .withProperty("database-name","database_name")
                                .withProperty("sink.properties.column_separator", "\x01")
                                .withProperty("sink.properties.row_delimiter", "\x02")
                                .withProperty("sink.buffer-flush.interval-ms", "10000")
                                .build(),
                        (slot,book)->{
                            slot[0] = book.id;
                            slot[1] = book.title;
                            slot[2] = book.authors;
                            slot[3] = book.year;
                        }
                )
        );

        env.execute();
    }
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/918869.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号