public Publisher(String binding, String topicName) throws Exception { mapper.setSerializationInclusion(Include.NON_NULL); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); context = ZMQ.context(1); publisher = context.socket(ZMQ.PUB); publisher.bind(binding); Thread.sleep(100); //System.out.println("Starting Publisher.."); publisher.setIdentity("B".getBytes()); publisher.setLinger(5000); publisher.setHWM(0); this.topicName = topicName; }
subscriber.setIdentity("hello".getBytes());
@Override public void run() { LOG.info("Started Worker " + identity); worker = context.createSocket(ZMQ.DEALER); worker.setIdentity(identity.getBytes()); worker.connect(bindAddr); try { loop(); } catch (ZMQException e) { if (e.getErrorCode() != ZMQ.Error.ETERM.getCode()) throw e; } context.destroy(); LOG.info("Ended Reader Worker " + identity); }
@Override public void run() { ZMQ.Socket socket = context.socket(ZMQ.DEALER); socket.setIdentity("shim".getBytes()); socket.connect("tcp://" + getAddress() + ":" + getPort()); LOG.info("Trying to connect to core on address tcp://" + getAddress() + ":" + getPort());
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); }
@Override public void run() { try { if (closed) { return; } if (null == zmq) { zmq = new ZContext(ioThreadCount); shutdownCtx = true; } socket = zmq.createSocket(socketType); socket.setIdentity(id.toString().getBytes()); configure(socket); pollin = new ZMQ.PollItem(socket, ZMQ.Poller.POLLIN); if (log.isDebugEnabled()) { zloop.verbose(true); } zloop.addPoller(pollin, inputHandler, null); start(socket); zloop.start(); zmq.destroySocket(socket); } catch (Exception e) { b.onError(e); } }
@Override public void run() { if (closed) { return; } if (null == zmq) { zmq = new ZContext(ioThreadCount); shutdownCtx = true; } socket = zmq.createSocket(socketType); socket.setIdentity(id.toString().getBytes()); configure(socket); pollin = new ZMQ.PollItem(socket, ZMQ.Poller.POLLIN); if (log.isTraceEnabled()) { zloop.verbose(true); } zloop.addPoller(pollin, inputHandler, null); start(socket); zloop.start(); zmq.destroySocket(socket); }
public WebMQPublisher(String port, String topic, String message) throws Exception { String binding = "tcp://*:" + port; context = ZMQ.context(1); publisher = context.socket(ZMQ.PUB); publisher.bind(binding); Thread.sleep(1000); publisher.setIdentity("B".getBytes()); publisher.setLinger(5000); publisher.setHWM(0); publisher.sendMore(topic); boolean isSent = publisher.send(message); publisher.close(); context.term(); } }
@Override public void run() { LOG.info("Started Worker " + identity); worker = context.createSocket(ZMQ.DEALER); worker.setRcvHWM(2000); worker.setIdentity(identity.getBytes()); worker.connect(bindAddr); try { loop(); } catch (ZMQException e) { if (e.getErrorCode() != ZMQ.Error.ETERM.getCode()) throw e; } LOG.info("Ended Writer Worker " + identity); context.destroy(); }
/** * A Topic handler that subscribes but has a publisher too. * @param paddress String. My TCP address for publishing. * @param addresses List. My TCP address and topics for listening. * @throws Exception */ public RTopic(String phandler, List<String> addresses) throws Exception { this(addresses); publisher = context.socket(ZMQ.PUB); publisher.bind(phandler); publisher.setIdentity("B".getBytes()); publisher.setLinger(5000); publisher.setHWM(0); }
public boolean SendData(byte[] data) { ZMsg msg = new ZMsg(); msg.add(data); ZMQ.Socket sendSocket = context.socket(ZMQ.PUSH); sendSocket.setIdentity("shim".getBytes()); sendSocket.connect(CONTROL_ADDRESS); send(msg, sendSocket); sendSocket.close(); return true; }
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; }