[zeromq-dev] Issues with Java bindings on Mac OS X 10.6.8
Joshua Foster
jhawk28 at gmail.com
Mon Aug 29 23:34:51 CEST 2011
You need to subscribe to the data. You don't receive any messages until a filter pattern is applied.
listener.subscribe("".getBytes());
Be aware that the Pub/Sub sockets are non durable and that they often lose the first set of messages send due to the time to connect and subscribe. You will want to add a sleep to the publisher after connect.
Joshua
On Aug 29, 2011, at 5:03 PM, Tero Paananen wrote:
> I'm having issues with getting pub / sub working on a Mac OS X 10.6.8
> using the Java bindings.
>
> Compiled and installed zeromq and jzmq using these instructions:
>
> http://antoniogarrote.wordpress.com/2010/09/08/zeromq-and-clojure-a-brief-introduction/
>
> (obviously with the latest versions of everything).
>
> Simple pub / sub example is not working:
>
>
> import org.zeromq.ZMQ;
> import org.zeromq.ZMQ.Context;
> import org.zeromq.ZMQ.Socket;
>
> public class subs {
> public static void main(String[] args) throws InterruptedException {
>
> Context context = ZMQ.context(1);
>
> Socket listener = context.socket(ZMQ.SUB);
> listener.bind("tcp://127.0.0.1:5560");
>
> byte[] message = listener.recv(0);
> String msg = new String(message);
> System.out.println(msg);
>
> listener.close();
> context.term();
> }
> }
>
>
>
> import org.zeromq.ZMQ;
> import org.zeromq.ZMQ.Context;
> import org.zeromq.ZMQ.Socket;
>
> public class publ {
> public static void main(String[] args) throws InterruptedException {
> Context context = ZMQ.context(1);
> Socket messenger = context.socket(ZMQ.PUB);
> messenger.connect("tcp://127.0.0.1:5560");
>
> messenger.send(args[0].getBytes(), 0);
>
> messenger.close();
> context.term();
> }
> }
>
> I start the subs, and run the publ. Publ executes, subs doesn't report
> receiving the message.
>
> I change the socket type on subs to ZMQ.PULL and everything works marvelously.
>
> Any ideas?
>
> I'm currently installing the same stack on a Ubuntu to see if it works
> on that platform.
>
> -TPP
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
More information about the zeromq-dev
mailing list