Tag Archives: zeromq

Using ZeroMQ Java Binding

  1. Ensure you have ZEROMQ_HOME environment variable pointing to the root source package (and compiled jars/dlls). See the compilation guide for more info.
  2. Ensure %ZEROMQ_HOME%\java\lib\zeromq.jar is on the classpath. The best way to achieve this if you’re using Maven is to deploy it to your internal repository so your work colleague can reference it directly.

    To deploy to internal maven repo:

    C:\> cd %ZEROMQ_HOME%\java\lib
    
    C:\zeromq-4.0.5\java\lib> mvn deploy:deploy-file -Dfile=zmq.jar -DgroupId=my.company.zmq -DartifactId=zmq -Dversion=3.1.0 Durl=file:////path/to/my/company/maven_repository
    

    To add this dependency on your project, add this to your pom.xml:

    
      my.company.zmq
      zmq
      3.1.0
    
    
    ...
    
     
      
        my-company-internal
        file:////path/to/my/company/maven_repository
      
    
    
  3. Set java system property java.library.path to %ZEROMQ_HOME%\java\lib. Note that java doesn’t accept environment variable, so you have to resolve it yourself. If you’re running through command line:
    C:\> java -Djava.library.path=C:\zeromq-4.0.5\java\lib
    

    On application servers like tomcat, you’ll have to edit the start script or the Windows service configuration. This system property has to be set before runtime starts, doing System.setProperty(key, value) will not work.

  4. Add %ZEROMQ_HOME%\bin\x64 to PATH env var:
    C:\>SET PATH=%ZEROMQ_HOME%\bin\x64;%PATH%
    

    If deploying on production server, this need to be done via Windows Advanced System Configuration. Make sure you restart any VM so it can pick up the latest env vars

  5. If you’re deploying on production environment, only following folder layout is required:
    C:\zeromq-4.0.5
     +- bin
         +- x64
             +- libzmq.dll
     +- java
         +- lib
             +- jzmq.dll
    

See Also

ZeroMQ Windows Java Binding: Building libzmq.dll, jzmq.dll and zmq.jar Using Visual Studio 2012

Versions used in this article:

  • jzmq-3.1.0
  • ZeroMQ-4.0.5 source
  • jdk 1.6.0 (Update 34), Windows 64bit
  • Visual Studio 2012
  • Windows 7 64bit

Build Steps

  1. Download , inflate it to C:\zeromq-4.0.5 (or other folder to your liking). Set your ZEROMQ_HOME environment variable pointing to this folder.
  2. Download , inflate it to %ZEROMQ_HOME%\java
  3. On %ZEROMQ_HOME%, open Visual Studio solution file builds\msvc\msvc10.sln. Switch the active profile to Release, and platform to x64. Perform Build Solution (F7). If successful you should get bin\x64\libzmq.dll
  4. On %ZEROMQ_HOME%\java, open Visual Studio solution file builds\msvc\msvc.sln. Switch the profile into Release
  5. Go to jzmq project property, edit the VC++ Directories. The include path has to correctly reference your jdk path (you can use environment variable like $(JAVA_HOME)). Similarly it also need reference to $(ZEROMQ_HOME)\include and ..\. ..\ is required so reference to config.hpp is not broken. Your Include Directories should end up similar like this:
    jzmq1
  6. Edit the Library Directories, and add $(JAVA_HOME)\lib and $(ZEROMQ_HOME)\lib. Your Library Directories should end up similar like this:
    jzmq2
  7. Do solution build. If all is successful you should end up with jzmq.dll and zmq.jar on %ZEROMQ_HOME%\java\lib
  8. You can now run the test program as mentioned on ZeroMQ Java Bindings doc:
    C:\>cd %ZEROMQ_HOME%\java\src\main\perf
    
    C:\zeromq-4.0.5\java\src\main\perf>set PATH=%ZEROMQ_HOME%\bin\x64;%PATH%
    
    C:\zeromq-4.0.5\java\src\main\perf>java -Djava.library.path=C:\zeromq-4.0.5\java\lib -classpath C:\zeromq-4.0.5\java\lib\zmq.jar;. local_lat tcp://127.0.0.1:5555 1 100
    

    Source code of these sample codes are available on %ZEROMQ_HOME%\java\src\main\perf in case you’re wondering what they do

See Also

Additional References

Setting Up ZeroMQ C++ On Visual Studio

This article is tested against following version / configuration:

  • Visual Studio 2012 (V110) Platform Toolset
  • Win32
  • ZeroMQ 4.0.4
  • Runtime Library: Multi-threaded DLL (/MD)

Steps to setup ZeroMQ on a Visual Studio C++ project:

  1. Download and install ZeroMQ-4.0.4~miru1.0-x86.exe (or newer) from http://zeromq.org/distro:microsoft-windows
  2. Set ZEROMQ_HOME environment variable to C:\Program Files (x86)\ZeroMQ 4.0.4 (or wherever you installed it to)
  3. On Visual Studio project configuration, add $(ZEROMQ_HOME)\include to Configuration Properties -> VC++ Directories. Don’t forget to restart Visual Studio so it picks up the new environment variable
  4. Add $(ZEROMQ_HOME)\lib to Linker -> General -> Additional Library Directories
  5. Add libzmq-v110-mt-4_0_4.lib to Linker -> Input -> Additional Dependencies
  6. Get a copy of zmq.hpp from , place this somewhere on your project. This header file references zmq.h located at $(ZEROMQ_HOME)\include
  7. Once you’ve compiled your executable, place libzmq-v110-mt-4_0_4.dll on the same folder, otherwise ZeroMQ initialisation will cause runtime crash

And finally take a look at some excellent tutorial examples from zeromq.org website to get you started, in particular:

See Also