Search in sources :

Example 1 with RELPEncoder

use of org.apache.nifi.processors.standard.relp.frame.RELPEncoder in project nifi by apache.

the class RELPFrameProducer method main.

public static void main(String[] args) {
    if (args == null || args.length != 5) {
        System.err.println("USAGE: RELPFrameProducer <HOST> <PORT> <NUM_MSGS> <DELAY_INTERVAL> <DELAY_MILLIS>");
        System.exit(1);
    }
    final String host = args[0];
    final int port = Integer.parseInt(args[1]);
    final int numMessages = Integer.parseInt(args[2]);
    final int delayInterval = Integer.parseInt(args[3]);
    final long delay = Long.parseLong(args[4]);
    final RELPEncoder encoder = new RELPEncoder(StandardCharsets.UTF_8);
    Socket socket = null;
    try {
        socket = new Socket(host, port);
        try (final OutputStream out = new BufferedOutputStream(socket.getOutputStream())) {
            // send the open frame
            out.write(encoder.encode(OPEN_FRAME));
            // send the specified number of syslog messages
            for (int i = 2; i < (numMessages + 2); i++) {
                final byte[] data = ("this is message # " + i).getBytes(StandardCharsets.UTF_8);
                final RELPFrame syslogFrame = new RELPFrame.Builder().txnr(i).command("syslog").dataLength(data.length).data(data).build();
                out.write(encoder.encode(syslogFrame));
                if (i % delayInterval == 0) {
                    System.out.println("Sent " + i + " messages");
                    out.flush();
                    Thread.sleep(delay);
                }
            }
            // send the close frame
            out.write(encoder.encode(CLOSE_FRAME));
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    } catch (final IOException e) {
        e.printStackTrace();
    } finally {
        IOUtils.closeQuietly(socket);
    }
}
Also used : RELPEncoder(org.apache.nifi.processors.standard.relp.frame.RELPEncoder) OutputStream(java.io.OutputStream) BufferedOutputStream(java.io.BufferedOutputStream) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream) Socket(java.net.Socket) RELPFrame(org.apache.nifi.processors.standard.relp.frame.RELPFrame)

Example 2 with RELPEncoder

use of org.apache.nifi.processors.standard.relp.frame.RELPEncoder in project nifi by apache.

the class TestListenRELP method setup.

@Before
public void setup() {
    encoder = new RELPEncoder(StandardCharsets.UTF_8);
    proc = new ResponseCapturingListenRELP();
    runner = TestRunners.newTestRunner(proc);
    runner.setProperty(ListenRELP.PORT, "0");
}
Also used : RELPEncoder(org.apache.nifi.processors.standard.relp.frame.RELPEncoder) Before(org.junit.Before)

Example 3 with RELPEncoder

use of org.apache.nifi.processors.standard.relp.frame.RELPEncoder in project nifi by apache.

the class ListenRELP method onScheduled.

@Override
@OnScheduled
public void onScheduled(ProcessContext context) throws IOException {
    super.onScheduled(context);
    // wanted to ensure charset was already populated here
    relpEncoder = new RELPEncoder(charset);
}
Also used : RELPEncoder(org.apache.nifi.processors.standard.relp.frame.RELPEncoder) OnScheduled(org.apache.nifi.annotation.lifecycle.OnScheduled)

Aggregations

RELPEncoder (org.apache.nifi.processors.standard.relp.frame.RELPEncoder)3 BufferedOutputStream (java.io.BufferedOutputStream)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 Socket (java.net.Socket)1 OnScheduled (org.apache.nifi.annotation.lifecycle.OnScheduled)1 RELPFrame (org.apache.nifi.processors.standard.relp.frame.RELPFrame)1 Before (org.junit.Before)1