Package org.zeromq.ZMQ

Examples of org.zeromq.ZMQ.Socket.connect()


        subscriber.connect("tcp://localhost:5561");
        subscriber.subscribe("".getBytes());

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

        //  - send a synchronization request
        syncclient.send("".getBytes(), 0);

        //  - wait for synchronization reply
View Full Code Here


        socket2.setLinger(0);
        socket2.setHWM(1);

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

        return Arrays.asList(socket1, socket2);
    }
}
View Full Code Here

        public void run(Object[] args, ZContext ctx, Socket pipe)
        {
            //  Subscribe to everything
            Socket subscriber = ctx.createSocket(ZMQ.SUB);
            subscriber.subscribe("".getBytes());
            subscriber.connect("tcp://localhost:5556");

            //  Get and process messages
            while (true) {
                String string = subscriber.recvStr();
                System.out.printf("%s\n", string);
View Full Code Here

    public static void main(String[] args) throws Exception
    {
        ZContext context = new ZContext();
        Socket publisher = context.createSocket(ZMQ.PUB);
        if (args.length == 1)
            publisher.connect(args[0]);
        else
            publisher.bind("tcp://*:5556");

        //  Ensure subscriber connection has time to complete
        Thread.sleep(1000);
View Full Code Here

        //  Set random identity to make tracing easier
        Random rand = new Random(System.nanoTime());
        String identity = String.format("%04X-%04X", rand.nextInt(0x10000), rand.nextInt(0x10000));
        worker.setIdentity(identity.getBytes());
        worker.connect("tcp://localhost:5556");

        //  Tell broker we're ready for work
        System.out.printf("I: (%s) worker ready\n", identity);
        ZFrame frame = new ZFrame(WORKER_READY);
        frame.send(worker, 0);
View Full Code Here

            Socket client = ctx.createSocket(ZMQ.DEALER);

            //  Set random identity to make tracing easier
            String identity = String.format("%04X-%04X", rand.nextInt(), rand.nextInt());
            client.setIdentity(identity.getBytes());
            client.connect("tcp://localhost:5570");

            PollItem[] items = new PollItem[] { new PollItem(client, Poller.POLLIN) };

            int requestNbr = 0;
            while (!Thread.currentThread().isInterrupted()) {
View Full Code Here

            this.ctx = ctx;
        }

        public void run() {
            Socket worker = ctx.createSocket(ZMQ.DEALER);
            worker.connect("inproc://backend");

            while (!Thread.currentThread().isInterrupted()) {
                //  The DEALER socket gives us the address envelope and message
                ZMsg msg = ZMsg.recvMsg(worker);
                ZFrame address = msg.pop();
View Full Code Here

            //  Get state snapshot if necessary
            if (srv.kvmap == null) {
                srv.kvmap = new HashMap<String, kvmsg>();
                Socket snapshot = srv.ctx.createSocket(ZMQ.DEALER);
                snapshot.connect(String.format("tcp://localhost:%d", srv.peer));

                System.out.printf("I: asking for snapshot from: tcp://localhost:%d",
                        srv.peer);
                snapshot.sendMore("ICANHAZ?");
                snapshot.send(""); // blank subtree to get all
View Full Code Here

            //  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);
View Full Code Here

            //  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);
View Full Code Here

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.