
Implementing the Pipes and Filters Pattern Using Actors in Akka for Java - DrLegend
http://iteratrlearning.com/java/2016/12/26/pipes-and-filters-actors-akka-java.html
======
yummyfajitas
This article is pretty silly. Why use Akka for this at all? You don't need an
untyped distributed system just to chain functions together. For logically
chaining functions together and accumulating errors, use Scalaz's \/:

[http://eed3si9n.com/learning-
scalaz/Either.html](http://eed3si9n.com/learning-scalaz/Either.html)

    
    
        text >>= (t => if (containsForbiddenWord) { MyError.left[String] } else { t.right[MyError] })
             >>= latexToUnicode _ 
             >>= ...etc...
    

Unlike actors, this is deterministic and easily testable code.

If you really need to use a fancy concurrent system for this, Akka already has
a built in piping/filtering framework called streams:

[http://doc.akka.io/docs/akka/2.4.16/scala/stream/index.html](http://doc.akka.io/docs/akka/2.4.16/scala/stream/index.html)

Unlike this actor example, streams comes with built in
backpressure/concurrency handling.

For new code you should probably be using streams rather than akka actors.

This article is neat for learning about actors, but you should almost
certainly not write production code this way.

~~~
hhandoko
Perhaps there was a constraint to use Java lang and not Scala, thus Scalaz
probably can't apply here.

~~~
yummyfajitas
True, I think of Akka as a Scala library but it works in Java too.

But I'm sure Java has some similar deterministic abstraction. I know Java used
to just use deterministic functions + exceptions, and that was hardly
unreasonable.

------
mpweiher
I've been experimenting with pipe/filter architectures on and off for quite
some time and so am very heartened to see renewed interest. In addition, I've
heard a lot (mostly good) about Akka but haven't had a chance to actually work
with it so this practical example is very welcome.

That said, the code I see seems very verbose, particularly the config part,
for what amounts to:

    
    
       text-checker | latex2unicode | upload-to-s3 
    

In my own Objective-C based P/F implementation, I currently deal with pipes as
arrays of filters, so it would be something like:

    
    
       [MPWPipe pipeWithFilters:@[ textChecker, latex2unicode, upload-to-s3 ]];
    

In Objective-Smalltalk, I'd think I can do better.

------
ryteu
An overengineered solution for a trivial problem. All you'd need is 3
functions. No reason at all to use Akka.

~~~
meddlepal
If you only see value in solving the problem then yea it's over engineered. If
you see value in learning a new technique for solving problems then it's a
solid example and write up.

Not everything has to be done for the sole purpose of being the best solution.

