本文整理汇总了Java中org.apache.flink.streaming.connectors.nifi.StandardNiFiDataPacket类的典型用法代码示例。如果您正苦于以下问题:Java StandardNiFiDataPacket类的具体用法?Java StandardNiFiDataPacket怎么用?Java StandardNiFiDataPacket使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StandardNiFiDataPacket类属于org.apache.flink.streaming.connectors.nifi包,在下文中一共展示了StandardNiFiDataPacket类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.apache.flink.streaming.connectors.nifi.StandardNiFiDataPacket; //导入依赖的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();
}
示例2: main
import org.apache.flink.streaming.connectors.nifi.StandardNiFiDataPacket; //导入依赖的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();
}
示例3: createNiFiDataPacket
import org.apache.flink.streaming.connectors.nifi.StandardNiFiDataPacket; //导入依赖的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);
}