Пример #1
0
  public static void main(String[] args) {
    Context context = ZMQ.context(1);

    //  First, connect our subscriber socket
    Socket subscriber = context.socket(ZMQ.SUB);
    subscriber.connect("tcp://localhost:5561");
    subscriber.subscribe(ZMQ.SUBSCRIPTION_ALL);

    //  Second, synchronize with publisher
    Socket syncclient = context.socket(ZMQ.REQ);
    syncclient.connect("tcp://localhost:5562");

    //  - send a synchronization request
    syncclient.send(ZMQ.MESSAGE_SEPARATOR, 0);

    //  - wait for synchronization reply
    syncclient.recv(0);

    //  Third, get our updates and report how many we got
    int update_nbr = 0;
    while (true) {
      String string = subscriber.recvStr(0);
      if (string.equals("END")) {
        break;
      }
      update_nbr++;
    }
    System.out.println("Received " + update_nbr + " updates.");

    subscriber.close();
    syncclient.close();
    context.term();
  }
Пример #2
0
  public static List<Socket> buildZPipe(final Context ctx) {
    final Socket socket1 = ctx.socket(ZMQ.PAIR);
    socket1.setLinger(0);
    socket1.setHWM(1);

    final Socket socket2 = ctx.socket(ZMQ.PAIR);
    socket2.setLinger(0);
    socket2.setHWM(1);

    final String iface = "inproc://" + new BigInteger(130, rand).toString(32);
    socket1.bind(iface);
    socket2.connect(iface);

    return Arrays.asList(socket1, socket2);
  }
Пример #3
0
    public Dealer(Context ctx, String name, int port) {
      s = ctx.socket(ZMQ.DEALER);
      this.name = name;
      this.port = port;

      s.setIdentity(name.getBytes(ZMQ.CHARSET));
    }
Пример #4
0
    public Client(Context ctx, String name, int port) {
      s = ctx.socket(ZMQ.REQ);
      this.name = name;
      this.port = port;

      s.setIdentity(name.getBytes(ZMQ.CHARSET));
    }
Пример #5
0
    @Override
    public void run() {
      Socket frontend = ctx.socket(ZMQ.ROUTER);

      assertNotNull(frontend);
      frontend.bind("tcp://127.0.0.1:" + frontendPort);

      Socket backend = ctx.socket(ZMQ.DEALER);
      assertNotNull(backend);
      backend.bind("tcp://127.0.0.1:" + backendPort);

      ZMQ.proxy(frontend, backend, null);

      frontend.close();
      backend.close();

      assert true;
    }
Пример #6
0
  public DistributedTraversal() {
    ImgGraph graph = ImgGraph.getInstance();
    context = graph.getZMQContext();
    if (context == null) System.out.println("context was null in DistributedTraversal");
    // Socket to talk to server
    requester = context.socket(ZMQ.REQ);

    managerIndex = graph.getNextTraversalManagerIndex();

    requester.connect("tcp://" + graph.getTraversalManagerIps()[managerIndex]);
  }
Пример #7
0
  //  We will do this all in one thread to emphasize the getSequence
  //  of events
  public static void main(String[] args) {
    Context context = ZMQ.context(1);

    Socket client = context.socket(ZMQ.ROUTER);
    client.bind("ipc://routing.ipc");

    Socket worker = context.socket(ZMQ.REP);
    worker.setIdentity("A".getBytes(ZMQ.CHARSET));
    worker.connect("ipc://routing.ipc");

    //  Wait for the worker to connect so that when we send a message
    //  with routing envelope, it will actually match the worker
    try {
      Thread.sleep(1000);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }

    //  Send papa address, address stack, empty part, and request
    client.send("A", ZMQ.SNDMORE);
    client.send("address 3", ZMQ.SNDMORE);
    client.send("address 2", ZMQ.SNDMORE);
    client.send("address 1", ZMQ.SNDMORE);
    client.send("", ZMQ.SNDMORE);
    client.send("This is the workload", 0);

    //  Worker should get just the workload
    ZHelper.dump(worker);

    //  We don't play with envelopes in the worker
    worker.send("This is the reply", 0);

    //  Now dump what we got off the ROUTER socket
    ZHelper.dump(client);

    client.close();
    worker.close();
    context.term();
  }
  @Override
  public void run() {
    ZMQ.Socket socket = context.socket(ZMQ.PULL);
    socket.connect(this.address);

    while (true) {

      String request = socket.recvStr(0);
      System.out.println(Thread.currentThread().getName() + " Received request: [" + request + "]");

      // Do some 'work'
      try {
        Thread.sleep(1000);
      } catch (InterruptedException e) {
      }
    }
  }
 public void init() {
   context = ZMQ.context(1);
   publisher = context.socket(ZMQ.PUB);
   publisher.bind("tcp://*:5563");
 }
Пример #10
0
 public static Socket socket(Context context, int type) {
   return context.socket(type);
 }