コード例 #1
0
    @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();
      }
    }
コード例 #2
0
    @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();
      }
    }