How to write custome ListenTCP processor in NiFi

1.6k Views Asked by At

I am going to read all streams in a TCP socket in network. the standard ListenTCP split streams based on \n (hard-coded). How I can write a custom ListenTCP processor in NiFi.

Do i need to extends AbstractListenEventProcessor? I rewrite all ListenTCP processor but it does not work.

1

There are 1 best solutions below

2
On

There is a JIRA for the processor to allow setting a configurable message delimiter: https://issues.apache.org/jira/browse/NIFI-1985

In order to implement this you need to modify the socket handlers that read the messages. The relevant code is here:

https://github.com/apache/nifi/blob/master/nifi-commons/nifi-processor-utilities/src/main/java/org/apache/nifi/processor/util/listen/handler/socket/StandardSocketChannelHandler.java#L136

And the same thing for SSL:

https://github.com/apache/nifi/blob/master/nifi-commons/nifi-processor-utilities/src/main/java/org/apache/nifi/processor/util/listen/handler/socket/StandardSocketChannelHandler.java#L136

It would be fairly easy to make the two handlers take the byte delimiter in the constructor, store it in a member variable, and then return that from getDelimiter(), and then you would have to get that byte passed all the way from the processor to when it creates the handler.

If you want to use more then one byte as a delimiter then it will be a little more challenging to do the comparison.