Note that there are some explanatory texts on larger screens.

plurals
  1. POZeroMQ / JZMQ - Subscriber message filtering NOT working
    primarykey
    data
    text
    <p>Message filtering does not work - fail to understand what is wrong with the code.This doesn't retrieve any msgs at all. Howevver if I use ("".getBytes()), it works fine and returns all msgs published. I'm using JZMQ2.1.3.jar. Please suggest. Thanks!!</p> <pre><code>public class OMQSubFilter { public static void main (String[] args) { // Prepare our context and subscriber Context context = ZMQ.context(1); Socket subscriber = context.socket(ZMQ.SUB); // System.out.print("Subscriber started"); subscriber.connect("tcp://localhost:5556"); // Subscribe to keywords, default is All String twtFilter = (args.length &gt; 0) ? args[0] : ""; subscriber.subscribe(twtFilter.trim().getBytes()); System.out.print("Filter: "+ twtFilter.trim()); while (!Thread.currentThread ().isInterrupted ()) { byte[] tweet = subscriber.recv(0); String str = new String(tweet); //String str = subscriber.recvStr(0).trim(); System.out.print(str); } subscriber.close (); context.term (); } } </code></pre> <p>And here is the publisher code:</p> <pre><code>public class OMQPub { public static void main (String[] args) { Context zcontext = ZMQ.context(1); Socket pub = zcontext.socket(ZMQ.PUB); pub.bind("tcp://*:5556"); java.util.List&lt;TweetStatus&gt; tweets = ct.getTweets(); Iterator&lt;TweetStatus&gt; iter = tweets.iterator(); String tweetStr = ""; try { Thread.sleep (1000); } catch (InterruptedException e) { e.printStackTrace(); } while (iter.hasNext()) { TweetStatus tweet = iter.next(); tweetStr = Utility.jsonFormat(tweet, ct.getKeywords()); System.out.println(" TweetStr : "+tweetStr); pub.send(tweetStr.getBytes(), ZMQ.NOBLOCK); } //pub.close(); //zcontext.term(); //zcontext.term() hangs even all the sockets created in the context are closed. } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload