public Pull(HttpServletResponse response, String port, String timeout, String limit) throws Exception { int lim = 1; if (limit != null) { lim = Integer.parseInt(limit); } ZMQ.Context context = ZMQ.context(1); ZMQ.Socket rcv = context.socket(ZMQ.PULL); rcv.bind("tcp://*:" + port); if (timeout != null) { int t = Integer.parseInt(timeout); rcv.setReceiveTimeOut(t); } int k = 0; while(k < lim || lim == 0) { String str = rcv.recvStr(); response.getWriter().println(str); k++; } rcv.close(); context.term(); } }
@Override public boolean initialize() { kryo.register(StreamElement4Rest.class); kryo.register(DataField[].class); AddressBean addressBean = getActiveAddressBean(); structure = getActiveAddressBean().getOutputStructure(); String _lport = addressBean.getPredicateValue("local_port"); laddress = addressBean.getPredicateValue("local_address"); if ( laddress == null || laddress.trim().length() == 0 ) throw new RuntimeException( "The >local_address< parameter is missing from the ZeroMQ wrapper." ); if (_lport != null){ lport = Integer.parseInt(_lport); if ( lport <= 0 || lport > 65535 ) throw new RuntimeException( "The >local_port< parameter must be a valid port number." ); } else { throw new RuntimeException( "The >local_port< parameter is missing from the ZeroMQ wrapper." ); } ZContext ctx = Main.getZmqContext(); receiver = ctx.createSocket(ZMQ.REP); receiver.bind("tcp://*:"+lport); receiver.setReceiveTimeOut(10000); return true; }
public void pull() { Runnable redisupdater = () -> { ZMQ.Context context = ZMQ.context(1); ZMQ.Socket rcv = context.socket(ZMQ.PULL); rcv.bind("tcp://*:8086"); rcv.setReceiveTimeOut(1000); String str = rcv.recvStr(); System.out.println("Received: " + str); rcv.close(); context.term(); }; Thread nthread = new Thread(redisupdater); nthread.start(); } }
requester.setReceiveTimeOut(1000); requester.setSendTimeOut(1000); requester.setLinger(0);
requester.setReceiveTimeOut(1000); requester.setSendTimeOut(1000); requester.connect((remoteContactPoint_META).trim());
subscriber.setReceiveTimeOut(1000); subscriber.setRcvHWM(0); // no limit subscriber.subscribe((vsensor+":").getBytes());
private JeroMqManager(final String name, final JeroMqConfiguration config) { super(null, name); publisher = CONTEXT.socket(ZMQ.PUB); publisher.setAffinity(config.affinity); publisher.setBacklog(config.backlog); publisher.setDelayAttachOnConnect(config.delayAttachOnConnect); if (config.identity != null) { publisher.setIdentity(config.identity); } publisher.setIPv4Only(config.ipv4Only); publisher.setLinger(config.linger); publisher.setMaxMsgSize(config.maxMsgSize); publisher.setRcvHWM(config.rcvHwm); publisher.setReceiveBufferSize(config.receiveBufferSize); publisher.setReceiveTimeOut(config.receiveTimeOut); publisher.setReconnectIVL(config.reconnectIVL); publisher.setReconnectIVLMax(config.reconnectIVLMax); publisher.setSendBufferSize(config.sendBufferSize); publisher.setSendTimeOut(config.sendTimeOut); publisher.setSndHWM(config.sndHwm); publisher.setTCPKeepAlive(config.tcpKeepAlive); publisher.setTCPKeepAliveCount(config.tcpKeepAliveCount); publisher.setTCPKeepAliveIdle(config.tcpKeepAliveIdle); publisher.setTCPKeepAliveInterval(config.tcpKeepAliveInterval); publisher.setXpubVerbose(config.xpubVerbose); for (final String endpoint : config.endpoints) { publisher.bind(endpoint); } LOGGER.debug("Created JeroMqManager with {}", config); }
receiver = ctx.createSocket(ZMQ.REP); receiver.bind("tcp://*:"+lport); receiver.setReceiveTimeOut(10000);
@Override public boolean configure(Properties properties) { try { listeningSocket = ctx.newSocket(method, type, listen); listeningSocket.setImmediate(false); listeningSocket.setReceiveTimeOut(-1); listeningSocket.setHWM(hwm); if(type == Sockets.SUB){ listeningSocket.subscribe(new byte[] {}); } boolean configured = super.configure(properties); stopPair = ctx.getPair(getName() + "/" + UUID.randomUUID()); return configured; } catch (org.zeromq.ZMQException e) { ZMQHelper.logZMQException(logger, "failed to start ZMQ input " + listen + ":", e); logger.catching(Level.DEBUG, e.getCause()); listeningSocket = null; return false; } }
@Override public DataField[] getOutputFormat() { if (structure == null){ requester = ctx.createSocket(ZMQ.REQ); requester.setReceiveTimeOut(1000); requester.setSendTimeOut(1000); requester.setLinger(0); requester.connect(remoteContactPoint_META); if (requester.send(vsensor + "?tcp://" + laddress + ":" + lport)){ byte[] rec = requester.recv(); if (rec != null){ structure = kryo.readObjectOrNull(new Input(new ByteArrayInputStream(rec)),DataField[].class); if (structure != null) requester.close(); return structure; } } requester.close(); } return structure; }
public RemoteCompleter(ZMQ.Socket socket) { this.socket = socket; socket.setReceiveTimeOut(5000); } @Override
@Override public ZMsg recv(int timeout) { final int old = pipe.getReceiveTimeOut(); pipe.setReceiveTimeOut(timeout); ZMsg msg = recv(true); pipe.setReceiveTimeOut(old); return msg; }
public Socket newSocket(Method method, Sockets type, String endpoint, int hwm, int timeout) { Socket socket = context.createSocket(type.ordinal()); socket.setRcvHWM(hwm); socket.setSndHWM(hwm); socket.setSendTimeOut(timeout); socket.setReceiveTimeOut(timeout); method.act(socket, endpoint); String url = endpoint + ":" + type.toString() + ":" + method.getSymbol(); socket.setIdentity(url.getBytes()); logger.debug("new socket: {}", url); return socket; }