Wednesday 4 May 2016

ZeroMQ (ØMQ) Distributed Messaging
[Setting up Visual Studio C++ Project for Client/Server Publisher/Subscriber Push/Pull Pair Architecture]

ZeroMQ (ØMQ) is an extension/library for Distributed Messaging on the bases of several different Architecture and Concepts.
  • Client/Server 
    • This is the most common architecture of message passing in which client sends a request with some predefined commands and server responds accordingly. Also referred as Request/Reply Pattern.
  • Publisher/Subscriber 
    • Publish/Subscribe is one of the classic pattern in which Publishers are the message senders and receivers are referred as Subscribers. Here messages are not programedto be sent directly to some specific receivers, instead messages are published without the knowledge of the receivers and depend on the subscriber of that knowledge exists.
  • Push/Pull 
    •  As also referred as Pipeline Pattern, distribute commands to multiple workers, arranged in a pipeline. Push sockets will distribute messages to its Pull clients evenly. Here, the results computed by consumer(the one pulling the message) are not sent upstream but downstream to another pull/consumer socket.
  • PAIR
    •  It provides sockets that are close in behavior to conventional sockets. Conventional sockets allow:
      • only strict one-to-one (two peers)
      • many-to-one (many clients, one server)
      • one-to-many (multicast) relationships

Setting Up ZeroMQ (ØMQ)

Let's start with a ZeroMQ (ØMQ)Installer, you can download from their Website. I will suggest you to select a latest version according to your operating system. I have used ZeroMQ version number 4.0.4 for 64Bit Windows Operating System. After the installation, navigate the your installed directory and you can find further folders namely: bin, doc, include, lib and other files as per the installation.

Setting Up the C++ Visual Studio Project

For the sake of simplicity create a New Project for C++ Console Application and then follow these following steps.
  1. Including the Headers
    • Right click Project -> Properties -> C/C++ -> General
    • Edit 'Additional Include Directories'
      • Add C:\Program Files\ZeroMQ 4.0.4\include
    • Right click 'Header Files' -> Add -> Existing Item -> C:\Program Files\ZeroMQ 4.0.4\include\zmq.h
  2. Adding the Library Directory
    •     Right click Project -> Properties -> Linker -> General
    •     Edit 'Additional Library Directories'
      •     Add C:\Program Files\ZeroMQ 4.0.4\lib\
  3. Linking to the proper Library
    •     Right click Project -> Properties -> General
    •     Check "Platform Toolset"
      • notice the version number (ex: v120)
    •     Configuration Properties -> Linker -> Input
    •     Edit 'Additional Dependencies'
      •     Add appopriate toolset library (ex: libzmq-v120-mt-gd-4_0_4.lib) "-gd-" is the debug version
  4. Ensure your App is 64-bit
    •     Build -> Configuration Manager
    •     Active solution platform -> New...
      •     Select x64
      •     Copy settings from Win32
    •     Right click Project -> Properties -> Linker -> All Options
    •     Edit "Output File"
      • set to ".\x64\Debug\whatever.exe"
  5. Include the pre-compiled Dll as a resource for Distribution
    •     Right click Project -> Properties -> Build Events -> Post-Build Event
    •     Edit "Command Line"
      •     insert copy command
      • example: copy /Y "C:\Program Files\ZeroMQ 4.0.4\bin\libzmq-v120-mt-gd-4_0_4.dll" "$(OutDir)"
Now, the setup is almost done as per the conventional setting up projects for external libraries in Visual Studio but the project is still not up and running. There's a slight addition for the .hpp file which needs to be downloaded and added explicitly as last stand alone part.

Which can be download from their Github Repository, placed in the same include directory as mentioned in Step#1 under the heading Setting up the Visual Studio Project and of course include this .hpp file as an existing item.

That's all for the setting up the ZeroMQ (ØMQ), start your application and have fun. In next few days, I will try to set up the basic client and server application on ZeroMQ (ØMQ). Cheers ;)

No comments:

Post a Comment