1

I'm trying to get a device running a native C build of ZMQ v 3.2.0 to work with a Java application built with JeroMQ (pure Java impl) using pub/sub ZMQ sockets. However, it seems that JeroMQ is using different flag configurations preceding the message payload vs. the C implementation. IIRC, JeroMQ is intended to be compatible with v 3.2.2, so I'm not sure if this is a bug in the JeroMQ port

My Java test code is similar the psenvpub example: public class psenvpub {

public static void main (String[] args) throws Exception {
    // Prepare our context and publisher
    Context context = ZMQ.context(1);
    Socket publisher = context.socket(ZMQ.PUB);

    publisher.bind("tcp://*:15052");
    byte seq = 1;
    while( !Thread.currentThread().isInterrupted() ){
        byte[] message = new byte[8];
        message[0] = 0;
        message[1] = 0;
        message[2] = 0;
        message[3] = 0;
        message[4] = seq++;
        message[5] = 0;
        message[6] = 0;
        message[7] = 0;
        publisher.send(message);
        try{
            Thread.sleep(1000);
        }
        catch(Exception e ){
            break;
        }
    }
}
}

I'm using a perl script for the Native C endpoint:

use strict;
use warnings;

use Vocollect::ZMQ::Context;
use ZMQ::Constants qw(ZMQ_SUB);

my $ctx = Vocollect::ZMQ::Context->new();
my $sock = $ctx->socket(ZMQ_SUB);
$sock->connect('tcp://localhost:15052');
$sock->subscribe('');

while (1) {
    my $msg = $sock->recv(10000);
    print "Received msg\n" if defined($msg);
}

When the subscriber receives its first message, it crashes due to an assert failure in the libzmq source code:

Assertion failed: options.recv_identity (..\..\..\src\socket_base.cpp:990)

Which is:

void zmq::socket_base_t::extract_flags (msg_t *msg_)
{
    //  Test whether IDENTITY flag is valid for this socket type.
    if (unlikely (msg_->flags () & msg_t::identity))
        zmq_assert (options.recv_identity);

    //  Remove MORE flag.
    rcvmore = msg_->flags () & msg_t::more ? true : false;
}

An wireshark trace of the packets sent shows that the handshaking sequence as well as the flags are different between a JeroMQ pub/sub and a native C pub/sub. I have not seen any issues when using endpoints that either both JeroMQ or both native C libzmq.

kart
  • 11
  • 2

0 Answers0