flink連線消費kafka
package flink.streaming import java.util.Properties import org.apache.flink.streaming.api.scala._ import org.apache.flink.streaming.connectors.kafka.FlinkKafkaConsumer import org.apache.flink.api.common.serialization.SimpleStringSchema import org.apache.flink.streaming.api.windowing.time.Time object StreamingTest { def main(args: Array[String]): Unit = { val kafkaProps = new Properties() //kafka的一些屬性 kafkaProps.setProperty("bootstrap.servers", "bigdata01:9092") //所在的消費組 kafkaProps.setProperty("group.id", "group1") //獲取當前的執行環境 val evn = StreamExecutionEnvironment.getExecutionEnvironment //kafka的consumer,test1是要消費的topic val kafkaSource = new FlinkKafkaConsumer[String]("test1",new SimpleStringSchema,kafkaProps) //設定從最新的offset開始消費 kafkaSource.setStartFromLatest() //自動提交offset kafkaSource.setCommitOffsetsOnCheckpoints(true) //flink的checkpoint的時間間隔 evn.enableCheckpointing(5000) //新增consumer val stream = evn.addSource(kafkaSource) stream.setParallelism(3) val text = stream.flatMap{ _.toLowerCase().split("\\W+")filter { _.nonEmpty} } .map{(_,1)} .keyBy(0) .timeWindow(Time.seconds(5)) .sum(1) text.print() //啟動執行 evn.execute("kafkawd") } }
//
pom.xml <project xmlns=" xsi:schemaLocation=" <modelVersion>4.0.0</modelVersion> <groupId>hgs</groupId> <artifactId>flink_lesson</artifactId> <version>1.0.0</version> <packaging>jar</packaging> <name>flink_lesson</name> <url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.1</version> <scope>test</scope> </dependency> <!-- <dependency> <groupId>org.apache.flink</groupId> <artifactId>flink-core</artifactId> <version>1.7.1</version> </dependency> <!-- <dependency> <groupId>org.apache.flink</groupId> <artifactId>flink-clients_2.12</artifactId> <version>1.7.1</version> </dependency> <!-- <dependency> <groupId>org.apache.flink</groupId> <artifactId>flink-streaming-scala_2.12</artifactId> <version>1.7.1</version> </dependency> <!-- <dependency> <groupId>org.apache.flink</groupId> <artifactId>flink-connector-kafka_2.12</artifactId> <version>1.7.1</version> </dependency> <!-- <dependency> <groupId>io.netty</groupId> <artifactId>netty-all</artifactId> <version>4.1.32.Final</version> </dependency> </dependencies> <build> <plugins> <plugin> <artifactId>maven-assembly-plugin</artifactId> <version>2.6</version> <configuration> <archive> <manifest> <!-- 我執行這個jar所執行的主類 --> <mainClass>hgs.flink_lesson.WordCount</mainClass> </manifest> </archive> <descriptorRefs> <descriptorRef> <!-- 必須是這樣寫 --> jar-with-dependencies </descriptorRef> </descriptorRefs> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> <plugin> <groupId>net.alchim31.maven</groupId> <artifactId>scala-maven-plugin</artifactId> <version>3.2.0</version> <executions> <execution> <goals> <goal>compile</goal> <goal>testCompile</goal> </goals> <configuration> <args> <!-- <arg>-make:transitive</arg> --> <arg>-dependencyfile</arg> <arg>${project.build.directory}/.scala_dependencies</arg> </args> </configuration> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.18.1</version> <configuration> <useFile>false</useFile> <disableXmlReport>true</disableXmlReport> <!-- If you have classpath issue like NoDefClassError,... --> <!-- useManifestOnlyJar>false</useManifestOnlyJar --> <includes> <include>**/*Test.*</include> <include>**/*Suite.*</include> </includes> </configuration> </plugin> </plugins> </build> </project>
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/31506529/viewspace-2564771/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 17-Flink消費Kafka寫入MysqlKafkaMySql
- kafka消費Kafka
- Kafka 消費組消費者分配策略Kafka
- Kafka 消費者解析Kafka
- Kafka - 消費介面分析Kafka
- kafka消費者消費訊息的流程Kafka
- 「Kafka應用」消費者Kafka
- Kafka 消費者組 RebalanceKafka
- Kafka之消費與心跳Kafka
- kafka消費者客戶端Kafka客戶端
- Kafka 1.0.0 多消費者示例Kafka
- java的kafka生產消費JavaKafka
- Kafka消費與心跳機制Kafka
- Businessvalue:用數字化連線消費者
- 實時數倉之Flink消費kafka訊息佇列資料入hbaseKafka佇列
- alpakka-kafka(7)-kafka應用案例,消費模式Kafka模式
- php連線kafkaPHPKafka
- Kafka入門(2):消費與位移Kafka
- 無鏡--kafka之消費者(四)Kafka
- spring 整合kafka監聽消費SpringKafka
- 使用Flume消費Kafka資料到HDFSKafka
- Kafka入門(4):深入消費者Kafka
- alpakka-kafka(8)-kafka資料消費模式實現Kafka模式
- Kafka 架構圖-輕鬆理解 kafka 生產消費Kafka架構
- 訊息推送平臺的實時數倉?!flink消費kafka訊息入到hiveKafkaHive
- Apache Kafka消費者再平衡 | TechMyTalkApacheKafka
- 【kafka】-分割槽-消費端負載均衡Kafka負載
- kafka中生產者和消費者APIKafkaAPI
- kafka java 生產消費程式demo示例KafkaJava
- kafka消費者提交方式(程式碼演示)Kafka
- kafka多執行緒順序消費Kafka執行緒
- Flink實戰:消費Wikipedia實時訊息
- 使用多執行緒增加kafka消費能力執行緒Kafka
- 探索Kafka消費者的內部結構Kafka
- 【Java面試】Kafka 怎麼避免重複消費Java面試Kafka
- Python指令碼消費多個Kafka topicPython指令碼Kafka
- Kafka - 消費錯誤問題,多臺機器上面無法消費資料Kafka
- Scrapy Kafka的連線使用Kafka