Understanding zeromq java binding

Alex Pritchard picture Alex Pritchard · Oct 24, 2012 · Viewed 8.2k times · Source

I'm investigating zeromq as a message passing solution in a java project, but I find the instructions on java binding somewhat difficult to follow. http://www.zeromq.org/bindings:java

I am unfamiliar with java bindings, so these may be stupid questions, but can someone help me understand:

  1. Why do I need to install anything?
  2. Will jars I build on one machine work on another system? I need this application to be portable.
  3. If so, why do I need to build my own jars to begin with?

I feel like the instructions provided on zeromq require base familiarity with building C projects that I lack, so perhaps I am just being dense, but this seems like a lot of work.

Answer

Guido Simone picture Guido Simone · Oct 24, 2012

As a fellow user of the Java binding of ZeroMQ, I sympathize. ZeroMQ is definitely one of the more challenging Java dependencies to manage. In it's heart of hearts, ZeroMQ is native C code and the Java binding is a (relatively) light weight wrapper around a JNI interface to the core ZeroMQ library and this is why it is complex to deploy.

As an aside - if ZeroMQ is a good match for your application, it's well worth the trouble because there really is nothing quite like it. Unfortunately this means you need to go through all these steps to get it working so you can decide if it is what you really need.

ZeroMQ for Java is based on three components:

  • libzmq - the core ZeroMQ library (DLL - required for any language, not just Java)
  • jzmq - the native portion of the Java binding (DLL)
  • zeromq.jar - the java portion of the Java binding (JAR)

Will jars I build on one machine work on another system? I need this application to be portable.

Yes. The jar will be portable. You can build it on any machine and deploy it on any other. However thats the easy part. The hard part is creating the various DLLs that are required and those are not portable. Let's say you want to support Windows, Mac and Fedora Linux. You will need native development environments on Windows, Mac and Fedora and build the DLLs for each platform you want to support.

I don't know enough about Linux to say whether a DLL built on one distribution (say Fedora) will run on another (say Debian). If not, then you have more work ahead.

Anyhow, your application will be portable - ZeroMQ and JZMQ can run on a huge number of platforms - but you will need to have tight control over your deployment process to ensure that when you install each platform, the jar and the appropriate set of DLLs are installed, and they are installed in the right place.

Why do I need to install anything?

Technically you don't. But I think they recommend doing the make install step so that the include and library files are where the compilers expect them and also so that Java can load them when it is time to run your program.

If so, why do I need to build my own jars to begin with?

I'm not a committer so I cannot say for sure. I expect part of it is developer efficiency - they would rather be improving the code than creating jars for users who could create the jars themselves.

More importantly - since the jars are not enough and you have to build the DLLs anyways, it makes more sense to build the jars and DLLs together. That way you are certain the JNI wrapper has exactly the right native methods implemented in C to match the native declarations in the Java wrapper class.

Good luck. Hope this helps.