Package org.zper.perf

Source Code of org.zper.perf.Producer

package org.zper.perf;

import java.util.Properties;

import org.zeromq.ZContext;
import org.zeromq.ZMQ;
import org.zeromq.ZMQ.Socket;
import org.zper.ZPUtils;

public class Producer
{
    private ZContext ctx;
    private Socket sock;

    public Producer(String topic, Properties props)
    {
        ctx = new ZContext();
        ctx.setLinger(-1);
        sock = ctx.createSocket(ZMQ.DEALER);
        sock.setSndHWM(0);
        sock.setIdentity(ZPUtils.genTopicIdentity(topic, 0));
        for (String addr : props.getProperty("writer.list").split(",")) {
            sock.connect("tcp://" + addr);
        }
    }

    public void send(Message message)
    {
        boolean rc;
        rc = sock.sendMore(message.getHeader());
        if (!rc)
            assert (false);
        rc = sock.send(message.getPayload());
        if (!rc)
            assert (false);

    }

    public void close()
    {
        ctx.destroy();
    }

}
TOP

Related Classes of org.zper.perf.Producer

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.