Flink学习 - 5. Flink之DataSource

DataSource

简单来说,DataSource是指数据来源,也是其字面意思,Flink无论是实时流计算还是批计算都基于数据进行,其数据源是非常重要的一部分,Flink在命名这一方面非常的直白,可以直接从字面意思来理解基本功能。

通常来说source的定义需要使用

StreamExecutionEnvironment.addSource(sourceFunction)

通过上述方法在程序中添加或者定义数据源。

Flink自带的DataSource

Flink官方定义了非常多的DataSource。如果需要可以直接使用对应的DataSource。


socket

  1. socketTextStream

监听一个端口,生成DataSource,并行度为1的DataSource

DataStreamSource<String> nums = env.socketTextStream("localhost", 12800);

给定元素

  1. fromElements()

一般用于单元测试程序或者调试代码使用,给定一些元素生成一个source。并行度是1的DataSource

Stream
025-05-12 11:53:53 org.apache.flink.util.FlinkException: Global failure triggered by OperatorCoordinator for 'Source: tproductorder[1] -> DropUpdateBefore[2] -> ConstraintEnforcer[3] -> Sink: ods_dts_nbg_nbgameaccount_tproductorder[3]' (operator cbc357ccb763df2852fee8c4fc7d55f2). at org.apache.flink.runtime.operators.coordination.OperatorCoordinatorHolder$LazyInitializedCoordinatorContext.failJob(OperatorCoordinatorHolder.java:624) at org.apache.flink.runtime.operators.coordination.RecreateOnResetOperatorCoordinator$QuiesceableContext.failJob(RecreateOnResetOperatorCoordinator.java:248) at org.apache.flink.runtime.source.coordinator.SourceCoordinatorContext.failJob(SourceCoordinatorContext.java:395) at org.apache.flink.runtime.source.coordinator.SourceCoordinator.start(SourceCoordinator.java:225) at org.apache.flink.runtime.operators.coordination.RecreateOnResetOperatorCoordinator$DeferrableCoordinator.resetAndStart(RecreateOnResetOperatorCoordinator.java:416) at org.apache.flink.runtime.operators.coordination.RecreateOnResetOperatorCoordinator.lambda$resetToCheckpoint$7(RecreateOnResetOperatorCoordinator.java:156) at java.util.concurrent.CompletableFuture.uniWhenComplete(CompletableFuture.java:774) at java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:750) at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:488) at java.util.concurrent.CompletableFuture.complete(CompletableFuture.java:1975) at org.apache.flink.runtime.operators.coordination.ComponentClosingUtils.lambda$closeAsyncWithTimeout$0(ComponentClosingUtils.java:77) at java.lang.Thread.run(Thread.java:750) Caused by: org.apache.flink.util.FlinkRuntimeException: org.apache.flink.util.FlinkRuntimeException: java.sql.SQLTransientConnectionException: connection-pool-192.168.2.5:3306 - Connection is not available, request timed out after 30000ms. at com.ververica.cdc.connectors.mysql.debezium.DebeziumUtils.openJdbcConnection(DebeziumUtils.java:64) at com.ververica.cdc.connectors.mysql.MySqlValidator.validate(MySqlValidator.java:72) at com.ververica.cdc.connectors.mysql.source.MySqlSource.createEnumerator(MySqlSource.java:170) at org.apache.flink.runtime.source.coordinator.SourceCoordinator.start(SourceCoordinator.java:221) ... 8 more Caused by: org.apache.flink.util.FlinkRuntimeException: java.sql.SQLTransientConnectionException: connection-pool-192.168.2.5:3306 - Connection is not available, request timed out after 30000ms. at com.ververica.cdc.connectors.mysql.source.connection.JdbcConnectionFactory.connect(JdbcConnectionFactory.java:72) at io.debezium.jdbc.JdbcConnection.connection(JdbcConnection.java:890) at io.debezium.jdbc.JdbcConnection.connection(JdbcConnection.java:885) at io.debezium.jdbc.JdbcConnection.connect(JdbcConnection.java:418) at com.ververica.cdc.connectors.mysql.debezium.DebeziumUtils.openJdbcConnection(DebeziumUtils.java:61) ... 11 more Caused by: java.sql.SQLTransientConnectionException: connection-pool-192.168.2.5:3306 - Connection is not available, request timed out after 30000ms. at com.ververica.cdc.connectors.shaded.com.zaxxer.hikari.pool.HikariPool.createTimeoutException(HikariPool.java:696) at com.ververica.cdc.connectors.shaded.com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:197) at com.ververica.cdc.connectors.shaded.com.zaxxer.hikari.pool.HikariPool.getConnection(HikariPool.java:162) at com.ververica.cdc.connectors.shaded.com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:100) at com.ververica.cdc.connectors.mysql.source.connection.JdbcConnectionFactory.connect(JdbcConnectionFactory.java:59)
最新发布
05-14
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值