Source:
<code>public static void main(String[] args) { ExampleArgs exArgs = ExampleUtils.readSubscribeArgs(args, usageString); System.out.printf("\nTrying to connect to %s, and listen to %s for %d messages.\n\n", exArgs.server, exArgs.subject, exArgs.msgCount); try (Connection nc = Nats.connect(ExampleUtils.createExampleOptions(exArgs.server, true))) { Dispatcher d = nc.createDispatcher(null); JetStream js = nc.jetStream(); CountDownLatch msgLatch = new CountDownLatch(exArgs.msgCount); MessageHandler handler = (Message msg) -> { System.out.printf("\nMessage Received:\n"); if (msg.hasHeaders()) { System.out.println(" Headers:"); for (String key: msg.getHeaders().keySet()) { for (String value : msg.getHeaders().values(key)) { System.out.printf(" %s: %s\n", key, value); } } } System.out.printf(" Subject: %s\n Data: %s\n", msg.getSubject(), new String(msg.getData(), StandardCharsets.UTF_8)); if (msg.isJetStream()) { MetaData meta = msg.metaData(); System.out.printf(" Stream Name: %s\n", meta.getStream()); System.out.printf(" Stream Seq: %d\n", meta.streamSequence()); System.out.printf(" Consumer Name: %s\n", meta.getConsumer()); System.out.printf(" Consumer Seq: %d\n", meta.consumerSequence()); } msgLatch.countDown(); }; <START> SubscribeOptions so = SubscribeOptions.builder().durable("sub-example").build(); <END> js.subscribe(exArgs.subject, d, handler, so); msgLatch.await(); System.out.printf("Received %d messages. Done.\n", exArgs.msgCount); } catch (Exception exp) { System.err.println(exp); } }</code><technical_language>sub-example option pass in, defaulting sub-example set</technical_language>

Target:
public static void main(String[] args) { ExampleArgs exArgs = ExampleUtils.readSubscribeArgs(args, usageString); System.out.printf("\nTrying to connect to %s, and listen to %s for %d messages.\n\n", exArgs.server, exArgs.subject, exArgs.msgCount); try (Connection nc = Nats.connect(ExampleUtils.createExampleOptions(exArgs.server, true))) { Dispatcher d = nc.createDispatcher(null); JetStream js = nc.jetStream(); if (exArgs.stream == null) { ExampleUtils.createTestStream(js, "test-stream", exArgs.subject); } CountDownLatch msgLatch = new CountDownLatch(exArgs.msgCount); MessageHandler handler = (Message msg) -> { System.out.printf("\nMessage Received:\n"); if (msg.hasHeaders()) { System.out.println(" Headers:"); for (String key: msg.getHeaders().keySet()) { for (String value : msg.getHeaders().values(key)) { System.out.printf(" %s: %s\n", key, value); } } } System.out.printf(" Subject: %s\n Data: %s\n", msg.getSubject(), new String(msg.getData(), StandardCharsets.UTF_8)); if (msg.isJetStream()) { MetaData meta = msg.metaData(); System.out.printf(" Stream Name: %s\n", meta.getStream()); System.out.printf(" Stream Seq: %d\n", meta.streamSequence()); System.out.printf(" Consumer Name: %s\n", meta.getConsumer()); System.out.printf(" Consumer Seq: %d\n", meta.consumerSequence()); } msgLatch.countDown(); }; SubscribeOptions so = SubscribeOptions.builder().durable("sub-example").build(); js.subscribe(exArgs.subject, d, handler, so); msgLatch.await(); System.out.printf("Received %d messages. Done.\n", exArgs.msgCount); } catch (Exception exp) { System.err.println(exp); } }