Ejemplo n.º 1
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();
  }
Ejemplo n.º 2
0
    @Override
    public void run(Object... args) {
      ZContext context = new ZContext();

      //  Prepare our context and sockets
      Socket client = context.createSocket(ZMQ.REQ);
      ZHelper.setId(client); //  Set a printable identity

      client.connect("ipc://frontend.ipc");

      //  Send request, get reply
      client.send("HELLO");
      String reply = client.recvStr();
      System.out.println("Client: " + reply);

      context.destroy();
    }
Ejemplo n.º 3
0
    @Override
    public void run(Object... args) {
      ZContext context = new ZContext();

      //  Prepare our context and sockets
      Socket worker = context.createSocket(ZMQ.REQ);
      ZHelper.setId(worker); //  Set a printable identity

      worker.connect("ipc://backend.ipc");

      //  Tell backend we're ready for work
      ZFrame frame = new ZFrame(WORKER_READY);
      frame.send(worker, 0);

      while (true) {
        ZMsg msg = ZMsg.recvMsg(worker);
        if (msg == null) break;

        msg.getLast().reset("OK");
        msg.send(worker);
      }
      context.destroy();
    }