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; }
/** * 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); }
/** * Configures a socket based on metadata. * * @param socket the socket * @param metadata the metadata */ public static void configure(ZMQ.Socket socket, ZeroMQMetadata metadata) { socket.setLinger(0); if (metadata.getHighWater() > -1) { socket.setHWM(metadata.getHighWater()); } else { socket.setHWM(1000); } if (metadata.getMulticastRate() > -1) { socket.setRate(metadata.getMulticastRate()); } if (metadata.getMulticastRecovery() > -1) { socket.setRecoveryInterval(metadata.getMulticastRecovery()); } if (metadata.getReceiveBuffer() > -1) { socket.setReceiveBufferSize(metadata.getReceiveBuffer()); } if (metadata.getSendBuffer() > -1) { socket.setSendBufferSize(metadata.getSendBuffer()); } } }
/** * Configures a socket based on metadata. * * @param socket the socket * @param metadata the metadata */ public static void configure(ZMQ.Socket socket, ZeroMQMetadata metadata) { socket.setLinger(0); if (metadata.getHighWater() > -1) { socket.setHWM(metadata.getHighWater()); } else { socket.setHWM(1000); } if (metadata.getMulticastRate() > -1) { socket.setRate(metadata.getMulticastRate()); } if (metadata.getMulticastRecovery() > -1) { socket.setRecoveryInterval(metadata.getMulticastRecovery()); } if (metadata.getReceiveBuffer() > -1) { socket.setReceiveBufferSize(metadata.getReceiveBuffer()); } if (metadata.getSendBuffer() > -1) { socket.setSendBufferSize(metadata.getSendBuffer()); } } }
@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; } }
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(); } }
public Socket[] getPair(String name) { String endPoint = "inproc://pair/" + name; Socket socket1 = newSocket(Method.BIND, Sockets.PAIR, endPoint); socket1.setLinger(0); socket1.setHWM(1); Socket socket2 = newSocket(Method.CONNECT, Sockets.PAIR, endPoint); socket2.setLinger(0); socket2.setHWM(1); return new Socket[] {socket1, socket2}; } }
public static Socket set_hwm(Socket socket, long hwm) { socket.setHWM(hwm); return socket; }