@Override public void run() { try { logger.debug("NATS Publisher ({}): Starting", id); io.nats.client.Connection c = new ConnectionFactory().createConnection(); for (int i = 0; i < testCount; i++) { c.publish(subject, NATS_PAYLOAD.getBytes()); tallyMessage(); } c.flush(); logger.debug("NATS Publisher ({}): Published {} messages.", id, testCount); setComplete(); } catch (Exception ex) { ex.printStackTrace(); } }
@Override public void run() { try { logger.trace("NATS Subscriber ({}): Subscribing to subject: {}", id, subject); io.nats.client.Connection c = new ConnectionFactory().createConnection(); AsyncSubscription s = c.subscribeAsync(subject, this); s.start(); setReady(); logger.debug("NATS Subscriber ({}): Subscribing to subject: {}", id, subject); waitForCompletion(); s.unsubscribe(); logger.debug("NATS Subscriber ({}): Exiting.", id); } catch (Exception ex) { ex.printStackTrace(); } }