Flink 快速入門案例二(參考官方文件)

2021-10-13 13:00:48 字數 2401 閱讀 2382

具有一定實際意義的流處理程式。

結合信用卡欺詐驗證場景,實現的具體demo。

package com.sanxiau;

import org.apache.flink.streaming.api.datastream.datastream;

import org.apache.flink.streaming.api.environment.streamexecutionenvironment;

import org.apache.flink.walkthrough.common.sink.alertsink;

import org.apache.flink.walkthrough.common.entity.alert;

import org.apache.flink.walkthrough.common.entity.transaction;

import org.apache.flink.walkthrough.common.source.transactionsource;

/** * 定義了程式的資料流

* * skeleton code for the datastream walkthrough

*/public

class

frauddetectionjob

}

package com.sanxiau;

import org.apache.flink.api.common.state.valuestate;

import org.apache.flink.api.common.state.valuestatedescriptor;

import org.apache.flink.api.common.typeinfo.types;

import org.apache.flink.configuration.configuration;

import org.apache.flink.streaming.api.functions.keyedprocessfunction;

import org.apache.flink.util.collector;

import org.apache.flink.walkthrough.common.entity.alert;

import org.apache.flink.walkthrough.common.entity.transaction;

/** * 對於每筆交易,欺詐檢測器都會檢查該帳戶的標記狀態

*/public

class

frauddetectortwo

extends

keyedprocessfunction

/***

* 具體 流資料 邏輯處理

* * @param transaction

* @param context

* @param collector

* @throws exception

*/@override

public

void

processelement

(transaction transaction, context context, collector

collector)

throws exception

// clean up our state

// 標記狀態被重置時,刪除定時器

cleanup

(context);}

// 交易數額小於 small_amount 設定定時器,進行欺詐驗證檢測

if(transaction.

getamount()

< small_amount)

}/**

* * 當定時器被觸發時,重置標記狀態。

* * @param timestamp

* @param ctx

* @param out

* @throws exception

*/@override

public

void

ontimer

(long timestamp, ontimercontext ctx, collector

out)

throws exception

/** * 標記狀態被重置時,刪除定時器

Flink快速入門二 Source程式設計

3.dataset source程式設計 當前主流的 tez spark flink 計算都是通過構建dag圖,然後觸發執行的。flink 的dataset和datastream的source程式設計很是類似。只是呼叫的api不一樣而已。source程式設計官網指導 datastream api 是...

gem5模擬器快速入門 四 (參考官方文件)

gem5附帶了許多配置指令碼,可讓您非常快速地使用gem5。但是,在使用gem5進行計算機體系結構研究時,充分了解要模擬的系統也很重要。我們可以在configs 中找到gem5的所有配置檔案。簡要說明如下 資料夾作用 boot 這些是在 full system 模式下使用的rcs檔案。這些檔案在li...

二 快速入門

一 springboot預設埠號為8080 在沒有主啟動類的情況下 package com.dudu.service import org.springframework.boot.autoconfigure.enableautoconfiguration import org.springfram...