ZeroMQ integration with Akka streams

Hello all!

I would like to use zeroMQ/0MQ/JeroMQ with akka to process messages with an external system.

Is there a sample integrating Akka Streams with Zero MQ?
I saw there was an old Alpakka extension but nothing up to date that works with latest Akka 2.6.x.

Any examples will be great. thanks.

Hi @gadieichhorn. ZeroMQ would be a nice integration to include with Alpakka. It’s been discussed before in an early Alpakka issue: https://github.com/akka/alpakka/issues/78 . If you’re interested, this is something that we could collaborate with you on to contribute into Alpakka as a community project.

1 Like

Thanks for getting back to me @seglo I am happy to help. I am not a Scala developer, I can use Java .

So far I made some pub / sub working but I was using Java threads to manage my zeroMQ sockets. I am sure there is a better way for Akka and streams.
How would I read from a blocking socket with Akka/Streams?

I created a SourceQueue and using offer to push elements to the stream after reading from the socket.

class Subscriber implements Runnable {

    private final ZMQ.Socket subscriber;

  ...
 
public void run() {
    ...
    while (!Thread.currentThread().isInterrupted()) {
            try {
                queue.offer(subscriber.recvStr());
            } catch (Exception ex) {
                log.warn("Exception", ex);
            }
        }

Questions:

  • Do I use external Threads or can I use the Akka executors?
  • Maybe I should use an Actor for this? If this is blocking then its not a good idea.

Thanks in advance.
Gadi.