Guest User

Can we customize a behaviour for in-mem queued messages afte

a guest
Dec 20th, 2013
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.07 KB | None | 0 0
  1. // Sender.
  2. public class ZSender {
  3.  
  4.     public static void main(String[] args) throws InterruptedException {
  5.         ZMQ.Context ctx = ZMQ.context(1);
  6.  
  7.         ZMQ.Socket client = ctx.socket(DEALER);
  8.         client.connect("tcp://" + args[0] + ":222");
  9.  
  10.         long i = 0;
  11.         while (true) {
  12.             assert client.send("", SNDMORE);
  13.             assert client.send(("hello" + i), 0);
  14.  
  15.             i++;
  16.             TimeUnit.SECONDS.sleep(1);
  17.         }
  18.     }
  19. }
  20. // Receiver.
  21. public class ZReceiver {
  22.  
  23.     public static void main(String[] args) throws InterruptedException {
  24.         ZMQ.Context ctx = ZMQ.context(1);
  25.  
  26.         ZMQ.Socket server = ctx.socket(ROUTER);
  27.         server.bind("tcp://*:222");
  28.  
  29.         while (true) {
  30.             byte[] identity = server.recv();
  31.             assert identity != null;
  32.  
  33.             byte[] div = server.recv();
  34.             assert div != null;
  35.  
  36.             byte[] hello = server.recv();
  37.             assert hello != null;
  38.  
  39.             System.out.println("receiver got: " + new String(hello));
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment