【Flink】广播流

       flink广播流适用于规则匹配,当规则数据比较少的情况,flink会把规则流广播,数据流就会拿到最新的规则流进行处理。

1、先定义规则类

package com.test;

import lombok.Data;

@Data
public class Rule {

    private Integer id;

    private String result;


    public Rule() {
    }

    public Rule(Integer id, String result) {
        this.id = id;
        this.result = result;
    }
}

2、定义规则流(待广播流)

package com.test;

import org.apache.flink.streaming.api.functions.source.SourceFunction;
/**
 * 自定义Source
 */
class RuleSourceFunction implements SourceFunction {
    private boolean isRunning = true;
    Integer id = 1;
    @Override
    public void run(SourceContext ctx) throws Exception {
        while (isRunning) {

            Rule rule = new Rule(id, "aaa");

            ctx.collect(rule);
            if (id == 1) {
                id = 2;
            }
  

你可能感兴趣的:(Flink实战,flink,css,html)