2

I am working in a desktop application, where application is deployed in both windows and mac platforms. As part of the application, it should communicate with native layer. Currently the communication between native layer and Java layer is done using sockets. Recently some one in the team suggested to use zeroMQ. Can any one of you guys please clarify my doubts.

  1. How zeroMQ better than sockets
  2. Is it possible to install zeroMQ library as part the Desktop client installation
  3. I gone through the link 'https://github.com/zeromq/clrzmq4', it given libraries specific to amd64 and i386 processor family. Do I need to build it separately from the source code for different processors?
  4. Do I still require .dll files to use zeroMQ in Java?
  5. Do I require Visual studio to build zeroMQ libraries in windows (Since my native layer written in C#, my C# application communicate with zeroMQ socket socket written java)?
  • Did you come across https://github.com/zeromq/jeromq ? Haven't used it, though. – Fildor Dec 13 '16 at 15:46
  • ZeroMQ is just a messaging queue that uses sockets. RabbitMQ is an alternative, and there are others. http://stackoverflow.com/questions/731233/activemq-or-rabbitmq-or-zeromq-or – OneCricketeer Dec 13 '16 at 15:48
  • Hi Fidor, I seen this, it is java implementation of zeroMQ. But my native layer is written in C#, so I need C# dll also to communicate with the socket application written in Java. I am confused with the 3rd and 5th points, I mentioned in the question –  Dec 13 '16 at 15:49
  • Thanks for the answer @cricket_007, but my question is not the diff between zeroMQ vs rabbitMQ. Is it possible to embed it with in desktop application? –  Dec 13 '16 at 15:51
  • And I'm simply saying if you cannot, then there are other alternatives. And it shouldn't matter if it is a desktop application, or server application. It's a library that communicates over a network layer, so it should be possible, yes. – OneCricketeer Dec 13 '16 at 15:53
  • @cricker_007 Thanks for the answer. If you had prior experience in using zeroMQ. Can you pls clarify the 3rd and 5ht points. –  Dec 13 '16 at 15:56
  • Can you clarify, please: You want to use ZeroMQ to communicate between a C# desktop application and a Java application? Are you passing small messages between them or large streams of data? – colini Dec 13 '16 at 17:33
  • Hi Colini, Yes, I want to use zeroMQ to communicate between a C# and Java application. I am passing both. Some are small strings and some data is of MBs in size –  Dec 13 '16 at 17:38

2 Answers2

1
  1. How zeroMQ better than sockets

    http://zeromq.org/topics:omq-is-just-sockets

  2. Is it possible to install zeroMQ library as part the Desktop client installation?

    Yes, you need to build the libraries depends on the processor and embed them in your application.

  3. Do I need to build it separately from the source code for different processors?

    Yes, you need to build the libraries from source. zeroMQ is processor centric.

  4. Do I still require .dll files to use zeroMQ in Java? Yes, Following link may help you

    Exception in thread "main" java.lang.UnsatisfiedLinkError: ... \jzmq.dll: Can't find dependent libraries

  5. Do I require Visual studio to build zeroMQ libraries in windows?

    Yes

This link may help you to get basic examples.

Community
  • 1
  • 1
Rk G
  • 26
  • 2
1

Regarding ZeroMQ in a desktop application on Windows talking to another process on the same machine, bear in mind that zmq_ipc is not supported (see zmq_ipc(7)). Or at least, that's the last I heard. This is because it's fundamentally impossible to implement anything like quite like select() or epoll() for named pipes in Windows. Just use zmq_tcp instead.

The same basic problem plagued the development of the select() implementation in Cygwin and its derivatives. They got round the problem by starting a thread for every non-socket file descriptor (i.e. named pipes, serial ports, etc) being selected, with each thread polling the HANDLE for whether any data had arrived (or whatever events were being set in select()). Not very efficient. Yeurk.

Proactor vs Reactor

Windows is proactor (which can do only proactor), everything else (*nix, VxWorks) is reactor (which can also be used to implement a proactor). The development of the boost.asio library for C++ was influenced by this, and is a proactor design as a result so that it could be run on Windows. RabbitMQ is proactor too.

ZeroMQ with zmq_poll() is reactor.

Proactor - you pro-actively start up an asynchronous routine to handle whatever turns up in the future.

Reactor - you react to the arrival of whatever has turned up by starting a synchronous call to whatever routine you wish to handle it knowing that it will complete very quickly because the data is already there.

The difference is key. In a proactor design, once you have started up that asynchronous routine to read a message, you cannot (easily) stop it or change it until it has done its thing. That is very annoying if you change your mind, for example as a result of reading some message from somewhere else.

Small caveat - Windows does support select() for network sockets (thus reactor programming is possible with network sockets, but only network sockets), and is the only reason why ZMQ is supported to any extent whatsoever on Windows.

Mixing ZMQ with Desktop Application Event Callbacks

Anyway, proactor means that Windows and C# fundamentally expects everything to be served by callbacks. This basically means you won't be using the zmq_poll() call to tell you if new messages have arrived if you also have callbacks handling GUI events. Instead you'd most likely be making asynchronous calls to zmq_revcmsg(). Trying to mix zmq_poll() in with callbacks is asking for trouble (you'd be blending proactor and reactor).

Message Formats

ZeroMQ and sockets both transfer bytes (as discrete messages with ZeroMQ, as a byte stream with sockets). One still has the challenge of deciding what the bytes mean to applications.

I can recommend using something like Google Protocol Buffers to serialise messages for transport by ZeroMQ. It's available for both C# and Java, but it doesn't demarcate message boundaries. Fortunately, ZeroMQ does. [Using GPB over a socket stream can be painful, you have to demarcate the message boundaries oneself]. So you can serialise a message to a buffer, hand the buffer over to ZeroMQ as a message, the recipient receives the message and knows for absolute certain that there is one single solitary GPB within. If you like you can use GPB's "oneof" to smuggle arbitrary message types across, which can be very liberating. You can accomplish the same with other serialisation technologies too of course, my personal favourite being ASN.1.

bazza
  • 7,580
  • 15
  • 22