国产亚洲精品福利在线无卡一,国产精久久一区二区三区,亚洲精品无码国模,精品久久久久久无码专区不卡

當(dāng)前位置: 首頁 > news >正文

常州做網(wǎng)站的公司有哪些今天實(shí)時熱搜榜排名

常州做網(wǎng)站的公司有哪些,今天實(shí)時熱搜榜排名,app推薦,網(wǎng)站上登錄系統(tǒng)制作大綱 新建工程自定義無界流 使用打包、提交、運(yùn)行工程代碼 在《Java版Flink使用指南——從RabbitMQ中隊(duì)列中接入消息流》一文中,我們讓外部組件RabbitMQ充當(dāng)了無界流的數(shù)據(jù)源,使得Flink進(jìn)行了流式處理。在《Java版Flink使用指南——將消息寫入到RabbitMQ…

大綱

  • 新建工程
    • 自定義無界流
  • 使用
  • 打包、提交、運(yùn)行
  • 工程代碼

在《Java版Flink使用指南——從RabbitMQ中隊(duì)列中接入消息流》一文中,我們讓外部組件RabbitMQ充當(dāng)了無界流的數(shù)據(jù)源,使得Flink進(jìn)行了流式處理。在《Java版Flink使用指南——將消息寫入到RabbitMQ的隊(duì)列中》一文中,我們使用了Flink自帶的數(shù)據(jù)生成器,生成了有限數(shù)據(jù),從而讓Flink以批處理形式運(yùn)行了該任務(wù)。
本文我們將自定義一個無界流生成器,以方便后續(xù)測試。

新建工程

我們新建一個名字叫UnboundedStreamGenerator的工程。
Archetype:org.apache.flink:flink-quickstart-java
版本:1.19.1
在這里插入圖片描述

自定義無界流

新建src/main/java/org/example/generator/UnBoundedStreamGenerator.java
然后UnBoundedStreamGenerator實(shí)現(xiàn)RichSourceFunction接口

public abstract class RichSourceFunction<OUT> extends AbstractRichFunctionimplements SourceFunction<OUT> {private static final long serialVersionUID = 1L;
}

主要實(shí)現(xiàn)SourceFunction接口的run和cancel方法。run方法用來獲取獲取,cancel方法用于終止任務(wù)。

package org.example.generator;import org.apache.flink.streaming.api.functions.source.RichSourceFunction;public class UnBoundedStreamGenerator extends RichSourceFunction<Long> {private volatile boolean isRunning = true;@Overridepublic void run(SourceContext<Long> ctx) throws Exception {long count = 0L;while (isRunning) {Thread.sleep(1000); // Simulate delayctx.collect(count++); // Emit data}}@Overridepublic void cancel() {isRunning = false;System.out.println("UnBoundedStreamGenerator canceled");}
}

在run方法中,我們每隔一秒產(chǎn)生一條數(shù)據(jù),且這個數(shù)字自增。

使用

我們使用addSource方法,將該無界流生成器添加成數(shù)據(jù)源。然后將其輸出到日志。

/** Licensed to the Apache Software Foundation (ASF) under one* or more contributor license agreements.  See the NOTICE file* distributed with this work for additional information* regarding copyright ownership.  The ASF licenses this file* to you under the Apache License, Version 2.0 (the* "License"); you may not use this file except in compliance* with the License.  You may obtain a copy of the License at**     http://www.apache.org/licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.*/package org.example;import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.example.generator.UnBoundedStreamGenerator;/*** Skeleton for a Flink DataStream Job.** <p>For a tutorial how to write a Flink application, check the* tutorials and examples on the <a href="https://flink.apache.org">Flink Website</a>.** <p>To package your application into a JAR file for execution, run* 'mvn clean package' on the command line.** <p>If you change the name of the main class (with the public static void main(String[] args))* method, change the respective entry in the POM.xml file (simply search for 'mainClass').*/
public class DataStreamJob {public static void main(String[] args) throws Exception {// Sets up the execution environment, which is the main entry point// to building Flink applications.final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();env.addSource(new UnBoundedStreamGenerator()).name("Custom Stream Source").setParallelism(1) .print(); // For demonstration, print the stream to stdout// Execute program, beginning computation.env.execute("Flink Java API Skeleton");}
}

打包、提交、運(yùn)行

在這里插入圖片描述
在這里插入圖片描述
在這里插入圖片描述
使用下面命令查看日志輸出

tail -f log/*

在這里插入圖片描述
然后我們在后臺點(diǎn)擊Cancel Job
在這里插入圖片描述
可以看到輸出
在這里插入圖片描述

工程代碼

https://github.com/f304646673/FlinkDemo

http://aloenet.com.cn/news/28069.html

相關(guān)文章:

  • 重慶今天最新消息漯河seo公司
  • wordpress站點(diǎn)全屏快速排名優(yōu)化推廣手機(jī)
  • 做金融類網(wǎng)站西安企業(yè)seo外包服務(wù)公司
  • 做html網(wǎng)站搜索框代碼新浪輿情通官網(wǎng)
  • asp網(wǎng)站搭建軟件南寧網(wǎng)站優(yōu)化
  • 代替手動修改網(wǎng)站模板標(biāo)簽seo標(biāo)題優(yōu)化分析范文
  • 網(wǎng)站標(biāo)題如何書寫軟文接單平臺
  • 泰州網(wǎng)站設(shè)計哪家好網(wǎng)上營銷的平臺有哪些
  • 網(wǎng)站建設(shè)技能描述免費(fèi)發(fā)布推廣平臺
  • nike網(wǎng)站建設(shè)方案診斷網(wǎng)站seo現(xiàn)狀的方法
  • 西安網(wǎng)站制作百億科技全國廣告投放平臺
  • 石家莊做網(wǎng)站的公司有哪些怎么制作鏈接網(wǎng)頁
  • 建模培訓(xùn)機(jī)構(gòu)優(yōu)化seo網(wǎng)站
  • 怎么在58上做公司網(wǎng)站企業(yè)網(wǎng)站推廣方案策劃
  • 幫網(wǎng)貸做網(wǎng)站會判刑嗎網(wǎng)站加速器
  • 個人網(wǎng)站營業(yè)執(zhí)照百度搜索引擎地址
  • WordPress P站優(yōu)化二十條
  • 如何做資源論壇網(wǎng)站百度推廣和優(yōu)化哪個好
  • 南昌網(wǎng)站建設(shè)費(fèi)用四川seo優(yōu)化
  • 做網(wǎng)站的要多錢百度關(guān)鍵詞優(yōu)化
  • 網(wǎng)站開發(fā)難點(diǎn)站長工具seo查詢
  • wordpress添加文章副標(biāo)題谷歌seo服務(wù)商
  • 泰興網(wǎng)站制作網(wǎng)絡(luò)營銷策劃方案模板
  • 搭建網(wǎng)站做財務(wù)系統(tǒng)網(wǎng)站建設(shè)流程步驟
  • 網(wǎng)友seo排名賺掛機(jī)
  • 成功網(wǎng)站管理系統(tǒng)十大網(wǎng)絡(luò)推廣公司排名
  • 做網(wǎng)站宣傳多少錢如何快速網(wǎng)絡(luò)推廣
  • 做網(wǎng)站的外包能學(xué)到什么磁力蜘蛛
  • 大連網(wǎng)站建設(shè)seo怎么去優(yōu)化
  • 重慶市衛(wèi)生健康委員會福州短視頻seo網(wǎng)站