Quantcast
Channel: Active questions tagged zeromq - Stack Overflow
Viewing all articles
Browse latest Browse all 193

How to receive a multipart message in ZMQ using Java?

$
0
0

As simple as this operation seems I can't find any documentation regarding how to receive a multipart message using ZMQ (Jeromq). I checked The Guide but it only contains C code with this info and it seems that I'm supposed to receive messages the same way no matter what kind of message I'm receiving.

In reality what happens is that I receive the multipart message in two messages with this code:

while (running.get()) {    items.poll();    if (items.pollin(0)) {        ByteArray message = receiver.recv(0);        System.out.println("Received " + String(message, Charset.forName("UTF-8")));    }}

The "Received" part will get printed twice if I send a multipart message like this:

publisher.sendMore(message.key);publisher.send(objectMapper.writeValueAsString(message.data));

What am I doing wrong?

Edit: I know there is a language selector below the examples but this particular problem is not present in any of the examples only explained inline with C code.

Edit

I tried to explore the API and found the hasReceiveMore() method. I tried using it, but it didn't work, I ended up with an infinite loop with this code:

List<String> parts = new ArrayList<>();while(receiver.hasReceiveMore()) {    parts.add(receiver.recvStr());}

Viewing all articles
Browse latest Browse all 193

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>