當前位置: 首頁>>代碼示例>>Java>>正文


Java NiFiDataPacket類代碼示例

本文整理匯總了Java中org.apache.flink.streaming.connectors.nifi.NiFiDataPacket的典型用法代碼示例。如果您正苦於以下問題:Java NiFiDataPacket類的具體用法?Java NiFiDataPacket怎麽用?Java NiFiDataPacket使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


NiFiDataPacket類屬於org.apache.flink.streaming.connectors.nifi包,在下文中一共展示了NiFiDataPacket類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import org.apache.flink.streaming.connectors.nifi.NiFiDataPacket; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
	StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

	SiteToSiteClientConfig clientConfig = new SiteToSiteClient.Builder()
			.url("http://localhost:8080/nifi")
			.portName("Data for Flink")
			.requestBatchCount(5)
			.buildConfig();

	SourceFunction<NiFiDataPacket> nifiSource = new NiFiSource(clientConfig);
	DataStream<NiFiDataPacket> streamSource = env.addSource(nifiSource).setParallelism(2);

	DataStream<String> dataStream = streamSource.map(new MapFunction<NiFiDataPacket, String>() {
		@Override
		public String map(NiFiDataPacket value) throws Exception {
			return new String(value.getContent(), Charset.defaultCharset());
		}
	});

	dataStream.print();
	env.execute();
}
 
開發者ID:axbaretto,項目名稱:flink,代碼行數:23,代碼來源:NiFiSourceTopologyExample.java

示例2: main

import org.apache.flink.streaming.connectors.nifi.NiFiDataPacket; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
	StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

	SiteToSiteClientConfig clientConfig = new SiteToSiteClient.Builder()
			.url("http://localhost:8080/nifi")
			.portName("Data from Flink")
			.buildConfig();

	DataStreamSink<String> dataStream = env.fromElements("one", "two", "three", "four", "five", "q")
			.addSink(new NiFiSink<>(clientConfig, new NiFiDataPacketBuilder<String>() {
				@Override
				public NiFiDataPacket createNiFiDataPacket(String s, RuntimeContext ctx) {
					return new StandardNiFiDataPacket(s.getBytes(ConfigConstants.DEFAULT_CHARSET),
						new HashMap<String, String>());
				}
			}));

	env.execute();
}
 
開發者ID:axbaretto,項目名稱:flink,代碼行數:20,代碼來源:NiFiSinkTopologyExample.java

示例3: main

import org.apache.flink.streaming.connectors.nifi.NiFiDataPacket; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
	StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

	SiteToSiteClientConfig clientConfig = new SiteToSiteClient.Builder()
			.url("http://localhost:8080/nifi")
			.portName("Data from Flink")
			.buildConfig();

	DataStreamSink<String> dataStream = env.fromElements("one", "two", "three", "four", "five", "q")
			.addSink(new NiFiSink<>(clientConfig, new NiFiDataPacketBuilder<String>() {
				@Override
				public NiFiDataPacket createNiFiDataPacket(String s, RuntimeContext ctx) {
					return new StandardNiFiDataPacket(s.getBytes(), new HashMap<String,String>());
				}
			}));

	env.execute();
}
 
開發者ID:axbaretto,項目名稱:flink,代碼行數:19,代碼來源:NiFiSinkTopologyExample.java

示例4: createNiFiDataPacket

import org.apache.flink.streaming.connectors.nifi.NiFiDataPacket; //導入依賴的package包/類
@Override
public NiFiDataPacket createNiFiDataPacket(LogLevels logLevels, RuntimeContext runtimeContext) {
    Map<String,Integer> counts = logLevels.getLevels();

    // get the total number of error and warn messages
    int totalWarnError = 0;
    if (counts.containsKey(ERROR)) {
        totalWarnError += counts.get(ERROR);
    }
    if (counts.containsKey(WARN)) {
        totalWarnError += counts.get(WARN);
    }

    // calculate the number of ERROR/WARN messages per second
    double windowSizeSeconds = windowSizeMillis / 1000;
    double actualRate = ((double)totalWarnError) / windowSizeSeconds;

    // always collect ERROR/WARN messages
    StringBuilder builder = new StringBuilder();
    builder.append(ERROR).append("\n");
    builder.append(WARN).append("\n");

    // only collect INFO and DEBUG if ERROR/WARN is less than minimum rate
    if (actualRate < minRatePerSecond) {
        builder.append(INFO).append("\n");
        builder.append(DEBUG).append("\n");
    }

    // pass the rate, total, and window size as attributes
    Map<String,String> attrs = new HashMap<>();
    attrs.put(ERROR_WARN_RATE_ATTR, String.valueOf(actualRate));
    attrs.put(ERROR_WARN_TOTAL_ATTR, String.valueOf(totalWarnError));
    attrs.put(WINDOW_MILLIS_ATTR, String.valueOf(windowSizeMillis));

    byte[] content = builder.toString().getBytes(StandardCharsets.UTF_8);
    return new StandardNiFiDataPacket(content, attrs);
}
 
開發者ID:bbende,項目名稱:nifi-streaming-examples,代碼行數:38,代碼來源:DictionaryBuilder.java

示例5: main

import org.apache.flink.streaming.connectors.nifi.NiFiDataPacket; //導入依賴的package包/類
public static void main(String[] args) throws Exception {
    String propertiesFile = DEFAULT_PROPERTIES_FILE;
    if (args != null && args.length == 1 && args[0] != null) {
        propertiesFile = args[0];
    }

    WindowLogLevelCountProps props = new WindowLogLevelCountProps(propertiesFile);

    // Set up the execution environment
    StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

    // Configure the SiteToSiteClient
    SiteToSiteClientConfig clientConfig = getSourceConfig(props);

    // Create our data stream with a NiFiSource
    SourceFunction<NiFiDataPacket> nifiSource = new NiFiSource(clientConfig);
    DataStream<NiFiDataPacket> streamSource = env.addSource(nifiSource);

    int windowSize = props.getFlinkWindowMillis();
    LogLevelFlatMap logLevelFlatMap = new LogLevelFlatMap(props.getLogLevelAttribute());

    // Count the occurrences of each log level over a window
    DataStream<LogLevels> counts =
            streamSource.flatMap(logLevelFlatMap)
                    .timeWindowAll(Time.of(windowSize, TimeUnit.MILLISECONDS))
                    .apply(new LogLevelWindowCounter());

    // Add the sink to send the dictionary back to NiFi
    double rateThreshold = props.getFlinkRateThreshold();
    SiteToSiteClientConfig sinkConfig = getSinkConfig(props);
    NiFiDataPacketBuilder<LogLevels> builder = new DictionaryBuilder(windowSize, rateThreshold);
    counts.addSink(new NiFiSink<>(sinkConfig, builder));

    // execute program
    env.execute("WindowLogLevelCount");
}
 
開發者ID:bbende,項目名稱:nifi-streaming-examples,代碼行數:37,代碼來源:WindowLogLevelCount.java

示例6: flatMap

import org.apache.flink.streaming.connectors.nifi.NiFiDataPacket; //導入依賴的package包/類
@Override
public void flatMap(NiFiDataPacket niFiDataPacket, Collector<LogLevel> collector)
        throws Exception {

    Map<String,String> attributes = niFiDataPacket.getAttributes();

    if (attributes.containsKey(attributeName)) {
        String logLevel = niFiDataPacket.getAttributes().get(attributeName);
        collector.collect(new LogLevel(logLevel, 1));
    }
}
 
開發者ID:bbende,項目名稱:nifi-streaming-examples,代碼行數:12,代碼來源:LogLevelFlatMap.java


注:本文中的org.apache.flink.streaming.connectors.nifi.NiFiDataPacket類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。