flink 从mysql 读取数据 放入kafka中 用于搜索全量

接着上一篇,将mysql的数据导入kafka中

public static void main(String[] arg) throws Exception {

        TypeInformation[] fieldTypes = new TypeInformation[] { BasicTypeInfo.STRING_TYPE_INFO };

        RowTypeInfo rowTypeInfo = new RowTypeInfo(fieldTypes);
        JDBCInputFormat jdbcInputFormat = JDBCInputFormat.buildJDBCInputFormat().setDrivername("com.mysql.jdbc.Driver")
                .setDBUrl("jdbc:mysql://*:3306/tablename?characterEncoding=utf8")
                .setUsername("*").setPassword("*")
                .setQuery("select LOGIC_CODE from *").setRowTypeInfo(rowTypeInfo).finish();

        final ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
        DataSource<Row> s = env.createInput(jdbcInputFormat);
        BatchTableEnvironment tableEnv = new BatchTableEnvironment(env, TableConfig.DEFAULT());
        tableEnv.registerDataSet("t2", s);
        Table query = tableEnv.sqlQuery("select * from t2");
        DataSet<String> result = tableEnv.toDataSet(query, Row.class).map(new MapFunction<Row, String>(){   
            @Override
              public String map(Row value) throws Exception {
                return value.toString() ;
              }

        });

        logger.info("read db end"); 

        KafkaOutputFormat kafkaOutput = KafkaOutputFormat.buildKafkaOutputFormat()
                .setBootstrapServers("*:9092").setTopic("search_test_whk").setAcks("all").setBatchSize("1000")
                .setBufferMemory("100000").setLingerMs("1").setRetries("2").finish();

        result.output(kafkaOutput);

        logger.info("write kafka end");

        env.execute("Flink add data source");

    }

相关文章

# 前言 现有主流消息中间件都是生产者-消费者模型,主要角色...
错误的根源是:kafka版本过高所致,2.2+=的版本,已经不需要...
DWS层主要是存放大宽表数据,此业务中主要是针对Kafka topic...
不多BB讲原理,只教你怎么用,看了全网没有比我更详细的了,...
终于写完了,其实最开始学kafka的时候是今年2月份,那时候还...
使用GPKafka实现Kafka数据导入Greenplum数据库踩坑问题记录(...