zeromq / czmq

High-level C binding for ØMQ
czmq.zeromq.org
Mozilla Public License 2.0
1.16k stars 523 forks source link

How to receive ZMsg on JMQ subscriber from a CZMQ publisher? #2198

Closed jhalter2 closed 2 years ago

jhalter2 commented 2 years ago

I'm trying to create a JMQ subscriber that will receive messages from a CZMQ publisher that is constantly running. I'm working on a very basic sample now where the CZMQ publisher sends out a simple zmsg in a loop and the JMQ subscriber is supposed to receive it, but my subscriber is never receiving a message.

//CZMQ publisher 
    zsock_t* _zmqCommand = zsock_new(ZMQ_PUB);
    zsock_bind(_zmqCommand, "tcp://*:5555");

    while (_run)
    {
        std::string message = "Hello from CZMQ";
        zframe_t* frame = zframe_new(message.data(), message.size());
        zmsg_t* msg = zmsg_new();

        zmsg_append(msg, &frame);
        _rc = zmsg_send(&msg, _zmqCommand);
        assert(_rc == 0);

        Sleep(1000);
    }
//JMQ subscriber
    private ZMQ.Context _context;
    private ZMQ.Socket  _subSocket;
    private ZMsg        _msg;
    private boolean     _success;

    {
        _context = ZMQ.context(1);

        assert(_context != null);
        assert(_subSocket == null);

        _subSocket = _context.socket(SocketType.SUB);
        _subSocket.subscribe("".getBytes());
        _success = _subSocket.connect("tcp://127.0.0.1:5555");

        assert(_success == true);

        _msg = ZMsg.recvMsg(_subSocket); //<-- never receive here
    }