Package

Source Code of Publisher

import org.zeromq.ZMQ;
import org.zeromq.ZMQ.Context;
import org.zeromq.ZMQ.Socket;

public class Publisher {
  public static void main(String[] args) {
    Context context = ZMQ.context(1);

    Socket socket = context.socket(ZMQ.PUB);
    socket.bind("tcp://localhost:5000");

    String[] topics = { "tech", "music", "design" };
    while (!Thread.currentThread().isInterrupted()) {
      for (int i = 0; i < topics.length; i++) {
        if (socket.send(topics[i], 0))
          System.out.println("Publish: " + topics[i]);
      }
    }

    socket.close();
    context.term();
  }
}
TOP

Related Classes of Publisher

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.