Search in sources :

Example 1 with SiteToSiteClientConfig

use of org.apache.nifi.remote.client.SiteToSiteClientConfig in project flink by apache.

the class NiFiSinkTopologyExample method main.

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();
}
Also used : SiteToSiteClient(org.apache.nifi.remote.client.SiteToSiteClient) NiFiDataPacketBuilder(org.apache.flink.streaming.connectors.nifi.NiFiDataPacketBuilder) SiteToSiteClientConfig(org.apache.nifi.remote.client.SiteToSiteClientConfig) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) StandardNiFiDataPacket(org.apache.flink.streaming.connectors.nifi.StandardNiFiDataPacket) RuntimeContext(org.apache.flink.api.common.functions.RuntimeContext)

Example 2 with SiteToSiteClientConfig

use of org.apache.nifi.remote.client.SiteToSiteClientConfig in project flink by apache.

the class NiFiSourceTopologyExample method main.

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();
}
Also used : SiteToSiteClientConfig(org.apache.nifi.remote.client.SiteToSiteClientConfig) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) NiFiSource(org.apache.flink.streaming.connectors.nifi.NiFiSource) NiFiDataPacket(org.apache.flink.streaming.connectors.nifi.NiFiDataPacket)

Aggregations

StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)2 SiteToSiteClientConfig (org.apache.nifi.remote.client.SiteToSiteClientConfig)2 RuntimeContext (org.apache.flink.api.common.functions.RuntimeContext)1 NiFiDataPacket (org.apache.flink.streaming.connectors.nifi.NiFiDataPacket)1 NiFiDataPacketBuilder (org.apache.flink.streaming.connectors.nifi.NiFiDataPacketBuilder)1 NiFiSource (org.apache.flink.streaming.connectors.nifi.NiFiSource)1 StandardNiFiDataPacket (org.apache.flink.streaming.connectors.nifi.StandardNiFiDataPacket)1 SiteToSiteClient (org.apache.nifi.remote.client.SiteToSiteClient)1