Git Product home page Git Product logo

nzmqt's Introduction

nzmqt - A lightweight C++ Qt binding for 0MQ

nzmqt is a lightweight C++ Qt binding for 0MQ / zeromq. The primary goal of this project is to provide a Qt-ish interface to 0MQ intelligent transport layer library and to integrate it into Qt's event loop seamlessly.

Why use nzmqt

If you use Qt framework for platform independent software development and you want to use 0MQ transport layer library you are facing the problem to integrate message queue into Qt's event system somehow. There is already a C++ Qt binding zeromqt which approaches this problem by integrating 0MQ into the Qt's event loop, mapping 0MQ message events onto Qt signals. Furthermore, it provides a Qt-like API which allows to represent messages as QByteArray instances. This is a nice idea! However, there are some drawbacks with the project's code and implementation, which is why I decided to start this project.

nzmqt is a re-implementation of the approach taken by zeromqt. I took the original implementation as a source of information, but I've done a completely new implementation. I could have built upon the exiting code by just forking it, but I wanted to be sure I can use the code in my projects without problems, because until now zeromqt's author hasn't officially released his work under a certain (open source) license. Consequently, nzmqt is released to the public under the simplified BSD license. So you can use the code in your (commercial) projects without any fear. Another short coming with zeromqt is that it works fine for 0MQ non-multi-part messages, but it doesn't support multi-part messages yet. Also, it duplicates a lot of code of 0MQ's standard C++ binding and, as a result, cannot profit from code improvements and bugfixes without copying or incorporating them into zeromqt's implementation. So in contrast to the original implementation, nzmqt reuses as much code of 0MQ's original C++ binding as possible by using inheritance. Additionally, several other things have been changed from an API user's perspective. In summary, nzmqt contains the following changes and improvements compared to zeromqt:

  • The implementation is a complete re-write in the sense that it doesn't duplicate code of 0MQ's official C++ binding anymore. Instead, it builds upon existing code through inheritance and, hence, will likely benefit from future bugfixes and enhancements targeted at 0MQ's C++ binding.
  • All classes are placed into a separate namespace 'nzmqt'.
  • 0MQ's multi-part messages are supported.
  • The initial support for using Qt's way of handling errors using error codes has been dropped. Instead, this code only throws exceptions originally thrown by 0MQ's official C++ API.
  • As with 0MQ's C++ binding all classes are contained within a singe header file which makes integrating this Qt binding very easy.
  • There is no 'ZmqContext' singleton anymore. Instead you can create your own instance of a concrete subclass of 'ZMQContext' yourself.
  • The socket class 'ZMQSocket' now also inherits from QObject, so you can add it as a child to any QObject parent as you know it from Qt.
  • The code is officially licensed under the (commercial-friendly) simplified BSD license.
  • Not only PUB-SUB, but also REQ-REP and PUSH-PULL are supported.

More Information

  • changelog: What's new? Read about changes introduced with each release.
  • nzmqt issue tracker: Find out about the current project status, or issue bug reports and feature requests.
  • software overview: How to get started, API reference documentation, etc.
  • samples overview: Explanation of the provided examples.

nzmqt's People

Contributors

beirdo avatar dceddia avatar dgtbarts avatar grefab avatar jellehissink avatar jonesmz avatar jonnydee avatar machinekoder avatar mwallnoefer avatar sampaioletti avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nzmqt's Issues

Exception thrown during poll

I have a REQ-REP socket pair and when I sent a message from REQ to REP, the REP side would throw a "Operation cannot be accomplished in current state" exception. It seems as though something was trying to receive the message twice.

I thought I had fixed the problem by moving the 2 lines around nzmqt.cpp:646 from the run() method into the bottom of the poll() method:

if (!m_stopped)
    QTimer::singleShot(m_interval, this, SLOT(run()));

A little more testing revealed that this did not fix the problem. Also, manually setting the polling interval to 500ms or even 1 second did not improve things. To complicate matters further, this same code all works great on a different machine (with a different version of CentOS and more CPUs, but same ZeroMQ and nzmqt).

I believe it's timing-related. Sticking a bunch of qDebug()s into poll() prevented the exception in the REP socket code, but then the REQ started having exceptions.

UPDATE: After running through gdb a bit, I found that hasMoreMessageParts() was returning true when it shouldn't. I noticed in the docs for zmq_getsockopt that the data type used for ZMQ_RCVMORE is int. I changed the type from quint64 to int and all seems to be well.

receiving messages from PyZMQ

I am trying to use the PUB/SUB pattern between a PyZMQ (python binding of zeroMQ) and nzmqt.
But I am not able to subscribe to messages comming from PyZMQ since the string format of the messages differ.
PyZMQ message: "topic message"
nzmqt: "MSG[topic: message]"
Is there a workaround for this or is it simply impossible to let PyZMQ and nzmqt talk to each other via PUB/SUB?

Destruction problem with Qt 4.8.0 on MacOSX Lion

I am not sure how to even start tracking this problem down. It might be me coding it wrong but I am getting an ASSERT every time the application quits.

By the looks of it, it seems to be caused by the destruction of PollingZMQContext.

The assert is on: ASSERT: "staticMetaObject.cast(_o)" in file moc_nzmqt.cpp, line 294

The offending code seems to be on line 415 of nzmqt.hpp:


 // Deleting children is necessary, because otherwise the children are deleted after the context
 // which results in a blocking state. So we delete the children before the zmq::context_t
 // destructor implementation is called.
        inline ~ZMQContext()
        {
            QObjectList children_ = children();
            foreach (QObject* child, children_)
                delete child;
        }

It is important to say that the problem only started to occur when I upgraded the Qt libs to 4.8.0. On 4.7.4, the problem was not being caused.

I am available at any time for debugging if necessary.

Thank you

ZMQ 4.2 causes trouble

I don't want to elaborate on this but I have serious trouble with ZMQ 4.2 and nzmqt. Memory management seems to work differently with newer ZMQ libs. In some instances I had to remove DONTWAIT in others I had to add additional try-catch blocks in the code.

Just in case anyone encounters the same problem.

Header-Only Doesn't Work?

Hi,
Is there any extra steps to get the header only include to work?
I try building my project as instructed with the nzmqt headers, but it seems that the linker complains all of the functions are not implemented.

undefined reference to 'vtable for nzmqt::ZMQContext` on ubuntu

I'm following the examples to create a console application that uses the pub-sub pattern using Qt on ubunutu. I'm using the include method of working with the code. When I try to compile my application I get several errors like:

undefined reference to 'vtable for nzmqt::ZMQContext'
undefined reference to 'vtable for nzmqt:;PollingZMQContext'

I opened all of the project files provided in the code and they all compile and run properly. Yet, when I try to include the <nzmqt/nzmqt.hpp> file, I get the error messages.

I'm using version 3.2.1 of nzmqt and 5.12.1 of Qt.

(Note: This relates to a post in the Qt forum: https://forum.qt.io/topic/100688/error-using-include-method-with-nzmqt-undefined-reference-to-vtable-for-nzmqt-zmqcontext )

warnings with -Wall (and compilation broken if -Werror)

We compile everything with -Wall -Werror.

With current git version of nzmqt it's not possible - there are commas at the end of enums, which lead to

nzmqt-3.2.0-dev/include/nzmqt/nzmqt.hpp:152:32: warning: comma at end of enumerator list [-pedantic]
nzmqt-3.2.0-dev/include/nzmqt/nzmqt.hpp:159:38: warning: comma at end of enumerator list [-pedantic]
nzmqt-3.2.0-dev/include/nzmqt/nzmqt.hpp:166:39: warning: comma at end of enumerator list [-pedantic]
nzmqt-3.2.0-dev/include/nzmqt/nzmqt.hpp:172:39: warning: comma at end of enumerator list [-pedantic]
nzmqt-3.2.0-dev/include/nzmqt/nzmqt.hpp:198:38: warning: comma at end of enumerator list [-pedantic]

Simply removing the last commas in the 5 enums [or 6 if you fix the commented-out one too] fixes it.

$ g++ --version
g++ (GCC) 4.7.1

Compilation on Windows

Do any instructions exist for compilation under Windows? The provided instructions aren't entirely complete for Windows, specifically regarding the usage of zmq.lib

Compilation issues at impl.hpp

At https://github.com/jonnydee/nzmqt/blob/master/include/nzmqt/impl.hpp#L87 I get an error in compiling using G++ 9.2.0.

Instead of QByteArray(data(), int(size())) the following seems to do the job:
QByteArray((char *) data(), int(size()))

./nzmqt/impl.hpp: In member function 'QByteArray nzmqt::ZMQMessage::toByteArray()':
./nzmqt/impl.hpp:90:43: error: expected primary-expression before '(' token
   90 |      return size() <= INT_MAX ? QByteArray(data<char>(), int(size())) : QByteArray();
      |                                           ^
./nzmqt/impl.hpp:90:49: error: expected primary-expression before 'char'
   90 |      return size() <= INT_MAX ? QByteArray(data<char>(), int(size())) : QByteArray();

zmq version

Just want to know in what version of zmq this binding can work.
Is this going to work with version 4.0.4?

Thanks

nzmqt and multiple instances

I recently came across an error when running nzmqt with multiple context screated from multiple classes. It was a segfault in the zmq lib probably caused by the multithreaded polling from more than one context (not thread-save?).

So my question is: Is there are preferred way of solving this problem with multiple classes creating multiple polling nzmqt contexts? Two possible solutions for this problem came to my mind:

  • Making PollingZMQContext a singleton
  • Using a global variable/property for managing the context

Have you already thought about that problem and what kind of solution would you prefer? I guess the singleton would be easier to implement and would keep people from mistakenly running in the problem I run into. However, the global property would probably be the more beautiful solution (and would require no changes to nzmqt)

Create 4.x Branch

Would the nzmqt team like to create a 4.x branch, or push 3.x from master to a branch. We are currently (we have a successful build) implementing the code using the latest libzmq (4.1.5) and have noticed a few changes that we may pull request once we have tested further. Since the repo has separated Branches by Major version number we don't want to start pulling into the master if that's not how its intended.

Thanks for the project.

issue with singleshot function

nzmqt/include/nzmqt/impl.hpp:458: error: no matching function for call to 'QTimer::singleShot(int, nzmqt::PollingZMQContext*, void (nzmqt::PollingZMQContext::*)())'
QTimer::singleShot(0, this, &PollingZMQContext::run);
^

ReqRep client does not receive response

I built nzmqt with zmq 2.1.11 on Windows 7 using the Qt SDK (Qt 4.7.4).

When running your Req-Rep example, there's no message received (only sent) and it just hangs there.

client output:
ReqRepClient::sendRequest> ("REQUEST[1: 2012-01-25T12:38:08]", "ping")

server output:
ReqRepServer::requestReceived> ("REQUEST[1: 2012-01-25T12:38:08]", "ping")
ReqRepServer::sendReply> ("REPLY[1: 2012-01-25T12:38:12]", "ping", "REQUEST[1: 2012-01-25T12:38:08]", "ping")

Doing a little bit of digging, it appears that socketReadActivity never gets called on the requester side even after a message comes in.

This may be related to this thread:

http://lists.zeromq.org/pipermail/zeromq-dev/2011-December/014688.html

but I'll do some more digging.

PyQt bindings

I would like to use nzmqt in my PyQt application, because in Python applications we have the same problems of integrating 2 event loops: zmq's and Qt's.

I've googled for PyQt bindings and didn't find any. I think it can be achieved with the help of SIP but I'm not sure because threading techniques in Python differs from the C++.

Is this project still Alive ?

Hi,

We are going to choose our messaging protocol and like zeromq.

We are at QT environment. We found this project promising.

Is it suppor latest zeromq branch ? still alive ?

Memory Leak when sending images

Hello,

I use the
NZMQT_INLINE bool ZMQSocket::sendMessage(const QByteArray& bytes_, SendFlags flags_)
function for sending a QByteArray of an QImage.

So I call
socket_->sendMessage(getImageCapture());
where getImageCapture() is:

QByteArray Example::getImageCapture()
{
    /* newimage holds an pointer to the image */
    QBuffer buffer;    
    if(!newImage)
        return NULL;   
    newImage->save(&buffer, "PNG");
    delete newImage;
    return buffer.buffer();
}

Everytime the memory increases. After a certain time I get a stackoverflow.

How can I handle this?

nzmq doesn't work with zmq 4.0.3

Please can you specify with which version of zeroMQ nzmqt works and a link to obtain it? Since nzmqt use zmq exceptions obviously with zmq > 3.0 it doesn't work, indeed all the code written reffers to the old api. Did you have any plan to support the new zmq api?
Thanks.

project setup on mac

i downloaded the repository and installed zmq using
brew install zmq

i still can not compile the static library
is there any other step that i should do?

zmg.h file is missing?

Compilation issue on Debian Stretch due to explicit keyword in CPPZMQ

Due to an explicit cast "issue" in some CPPZMQ versions (zeromq/cppzmq@bd288a5) (i.e. it happend on Debian Stretch for me), nzmqt cannot compile using newer compilers.

Fix:
Fix affects file: /include/nzmqt/impl.hpp
Function: NZMQT_INLINE void PollingZMQContext::registerSocket(ZMQSocket* socket_)

Change: Force cast to void* when creating new pollitem:
from: pollitem_t pollItem = { socket_, 0, ZMQSocket::EVT_POLLIN, 0 };
to: pollitem_t pollItem = { static_cast<void
>(*socket_), 0, ZMQSocket::EVT_POLLIN, 0 };

setup script

Hi,
I am new to ZMQ and trying to install nzmqt .
https://github.com/jonnydee/nzmqt/blob/master/doc/Software.md
Trying to install nzmqt in Linux with Zeomq (c/c++ binding)
On the setup script part. I can not find the setup-project.sh script, not sure, i am missing some info

cd
./setup-project.sh

Secondly is this library work with ZeroMQ Zyre framework?

Adding security to nzmqt

Hello,

Thanks for the great work,
Did you consider before to have security in the project? are there any momentom to that?

Tests do not compile

I followed the getting started guide, and then tried compiling the tests, but this failed with lots of the following errors:
g++ -c -pipe -O2 -Wall -Wextra -D_REENTRANT -fPIC -DSRCDIR=\"/home/simon/nzmqt/src/\" -DQT_NO_DEBUG -DQT_TESTLIB_LIB -DQT_CORE_LIB -DQT_TESTCASE_BUILDDIR='"/home/simon/nzmqt/src"' -I. -I../include -I../externals/include -I/include -I/opt/local/include -I/opt/Qt/5.15.2/gcc_64/include -I/opt/Qt/5.15.2/gcc_64/include/QtTest -I/opt/Qt/5.15.2/gcc_64/include/QtCore -I. -I/opt/Qt/5.15.2/gcc_64/mkspecs/linux-g++ -o nzmqt_test.o test/nzmqt_test.cpp In file included from ../include/nzmqt/nzmqt.hpp:32, from ./common/SampleBase.hpp:30, from ./pubsub/Publisher.hpp:30, from test/nzmqt_test.cpp:27: ../externals/include/zmq.hpp:550:47: error: ‘zmq_event_t’ does not name a type 550 | virtual void on_event_connected(const zmq_event_t &event_, const char* addr_) { (void)event_; (void)addr_; } | ^~~~~~~~~~~ ../externals/include/zmq.hpp:551:53: error: ‘zmq_event_t’ does not name a type 551 | virtual void on_event_connect_delayed(const zmq_event_t &event_, const char* addr_) { (void)event_; (void)addr_; } | ^~~~~~~~~~~ ../externals/include/zmq.hpp:552:53: error: ‘zmq_event_t’ does not name a type 552 | virtual void on_event_connect_retried(const zmq_event_t &event_, const char* addr_) { (void)event_; (void)addr_; } | ^~~~~~~~~~~
Maybe there is a step missing from the guide?

I performed the following steps:

  1. Install Qt version 5.15.2
  2. Install ZeroMQ: sudo apt install libzmq3-dev
  3. Get nzmqt: git clone https://github.com/jonnydee/nzmqt.git
  4. cd nzmqt
  5. git checkout version-3.2.0
  6. ./setup-project.sh
  7. cd src
  8. qmake nzmqt_test.pro
  9. make

My setup:
Ubuntu 21.10
gcc version 11.2.0
make version 4.3

ROUTER-DEALER

Does this library support 0mq pattern router-dealer?

A problem!

when network disconnected. Then connected later. A problem come, the QAMQP client cannot get any message from queue again!

Possible typo in PollingZMQContext::registerSocket()

Greetings!

I'm trying nzmqt on Ubuntu 16.04 LTS (gcc 5.4.0) with Qt 5.5.1 (default). ZeroMQ was installed from libzmq3-dev. These are not important details, mentioning it just to be on the safe side.

Everything works well with cppzmq included, but I've noticed the following (impl.hpp):

NZMQT_INLINE void PollingZMQContext::registerSocket(ZMQSocket* socket_)
{
    pollitem_t pollItem = { *socket_, 0, ZMQSocket::EVT_POLLIN, 0 };

    QMutexLocker lock(&m_pollItemsMutex);

    m_pollItems.push_back(pollItem);

    super::registerSocket(socket_);
}

That struct, pollitem_t is defined in zmq.h as follows:

typedef struct zmq_pollitem_t
{
    void *socket;
#if defined _WIN32
    SOCKET fd;
#else
    int fd;
#endif
    short events;
    short revents;
} zmq_pollitem_t;

I'm a C++ programmer, not so very good with pure C and it's kinky options, but doesn't that mean assigning a dereferenced pointer (socket) to the void* field of the structure? Perhaps, dereferencing is not required there?

Like... pollitem_t pollItem = { socket_, 0, ZMQSocket::EVT_POLLIN, 0 };

It never causes any compilation problems, al least with cppzmq included, but looks suspicious a bit.

Unsafe disconnect in PollingZMQContext::unregisterSocket(QObject* socket_)

It seems unsafe (and unnecessary) to call disconnect on socket_ when unregisterSocket is called from socket_'s destroyed signal. If socket_ is has been created in a different thread than the PollingZMQContext instance was created in, the destroyed signal will arrive after socket_ has been destroyed, leading to a free memory read.

This seems to be the cause of some crashes reported in MythTV, http://code.mythtv.org/trac/ticket/10924, http://code.mythtv.org/trac/ticket/11043, http://code.mythtv.org/trac/ticket/11360.

Valgrind log is available at http://code.mythtv.org/trac/attachment/ticket/10924/valgrind-mythlogserver.txt.

not able to use nzmq for QT windows msvc compiler

Hi, I have used nzmq for android and linux qt project in that it is working perfectly.
but same project when I compiled in QT for windows msvc 17 it is not able to use zmq.h file.
I added library support for windows still not working
can someone help me with this....
I need library for qt windows mscv 2017

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.