Skip to content

Commit

Permalink
last ack and remove gap detection (#552)
Browse files Browse the repository at this point in the history
  • Loading branch information
scottf authored Oct 27, 2021
1 parent 83d401c commit 7525652
Show file tree
Hide file tree
Showing 39 changed files with 684 additions and 1,238 deletions.
15 changes: 0 additions & 15 deletions src/examples/java/io/nats/examples/ExampleArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,6 @@ public static Builder builder(String title, String[] args, String usage) {
return new Builder(title, args, usage);
}

// TODO REMOVE THIS
public static Builder builder() {
return new Builder(null, null, null);
}

public static class Builder {

private final ExampleArgs ea;
Expand Down Expand Up @@ -289,16 +284,6 @@ public ExampleArgs build() {
ea.displayBanner();
return ea;
}

@Deprecated // Old Style
public ExampleArgs build(String[] args, String usage) {
ea.parse(args, null, usage);
if (ea.containedUnknown && usage != null) {
usageThenExit(usage);
}
ea.displayBanner();
return ea;
}
}

private static void usageThenExit(String usageString) {
Expand Down
79 changes: 45 additions & 34 deletions src/examples/java/io/nats/examples/ExampleUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,52 +31,63 @@ public static String getServer(String[] args) {

public static Options createExampleOptions(String[] args) throws Exception {
String server = getServer(args);
return createExampleOptions(server, false);
return createExampleOptions(server, false, null);
}

public static Options createExampleOptions(String[] args, boolean allowReconnect) throws Exception {
String server = getServer(args);
return createExampleOptions(server, allowReconnect);
return createExampleOptions(server, allowReconnect, null);
}

public static Options createExampleOptions(String server) throws Exception {
return createExampleOptions(server, false);
return createExampleOptions(server, false, null);
}

public static Options createExampleOptions(String server, ErrorListener el) throws Exception {
return createExampleOptions(server, false, el);
}

public static Options createExampleOptions(String server, boolean allowReconnect) throws Exception {
Options.Builder builder = new Options.Builder()
.server(server)
.connectionTimeout(Duration.ofSeconds(5))
.pingInterval(Duration.ofSeconds(10))
.reconnectWait(Duration.ofSeconds(1))
.errorListener(new ErrorListener() {
public void exceptionOccurred(Connection conn, Exception exp) {
System.out.println("Exception " + exp.getMessage());
}

public void errorOccurred(Connection conn, String type) {
System.out.println("Error " + type);
}

public void slowConsumerDetected(Connection conn, Consumer consumer) {
System.out.println("Slow consumer");
}
})
.connectionListener((conn, type) -> System.out.println("Status change "+type));

if (!allowReconnect) {
builder = builder.noReconnect();
} else {
builder = builder.maxReconnects(-1);
}
return createExampleOptions(server, allowReconnect, null);
}

if (System.getenv("NATS_NKEY") != null && System.getenv("NATS_NKEY") != "") {
AuthHandler handler = new ExampleAuthHandler(System.getenv("NATS_NKEY"));
builder.authHandler(handler);
} else if (System.getenv("NATS_CREDS") != null && System.getenv("NATS_CREDS") != "") {
builder.authHandler(Nats.credentials(System.getenv("NATS_CREDS")));
}
public static Options createExampleOptions(String server, boolean allowReconnect, ErrorListener el) throws Exception {
if (el == null) {
el = new ErrorListener() {
public void exceptionOccurred(Connection conn, Exception exp) {
System.out.println("Exception " + exp.getMessage());
}

public void errorOccurred(Connection conn, String type) {
System.out.println("Error " + type);
}

public void slowConsumerDetected(Connection conn, Consumer consumer) {
System.out.println("Slow consumer");
}
};
}

Options.Builder builder = new Options.Builder()
.server(server)
.connectionTimeout(Duration.ofSeconds(5))
.pingInterval(Duration.ofSeconds(10))
.reconnectWait(Duration.ofSeconds(1))
.errorListener(el)
.connectionListener((conn, type) -> System.out.println("Status change "+type));

if (!allowReconnect) {
builder = builder.noReconnect();
} else {
builder = builder.maxReconnects(-1);
}

if (System.getenv("NATS_NKEY") != null && System.getenv("NATS_NKEY") != "") {
AuthHandler handler = new ExampleAuthHandler(System.getenv("NATS_NKEY"));
builder.authHandler(handler);
} else if (System.getenv("NATS_CREDS") != null && System.getenv("NATS_CREDS") != "") {
builder.authHandler(Nats.credentials(System.getenv("NATS_CREDS")));
}
return builder.build();
}

Expand Down
4 changes: 2 additions & 2 deletions src/examples/java/io/nats/examples/NatsPubMany.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ public class NatsPubMany {
+ "\nUse the URL for user/pass/token authentication.\n";

public static void main(String[] args) {
ExampleArgs exArgs = ExampleArgs.builder()
ExampleArgs exArgs = ExampleArgs.builder("Core Publish Many Messages", args, usageString)
.defaultSubject("example-subject")
.defaultMessage("hello")
.defaultMsgCount(10)
.build(args, usageString);
.build();

try (Connection nc = Nats.connect(ExampleUtils.createExampleOptions(exArgs.server, false))) {

Expand Down
150 changes: 0 additions & 150 deletions src/examples/java/io/nats/examples/NatsSubQueueFull.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ public class NatsJsMirrorSubUseCases {
+ "\nUse the URL in the -s server parameter for user/pass/token authentication.\n";

public static void main(String[] args) {
ExampleArgs exArgs = ExampleArgs.builder()
ExampleArgs exArgs = ExampleArgs.builder("Mirror Subscription Use Cases", args, usageString)
.defaultStream("example-stream")
.defaultMirror("example-mirror")
.defaultSubject("example-subject")
.defaultDurable("example-durable")
.build(args, usageString);
.build();

try (Connection nc = Nats.connect(ExampleUtils.createExampleOptions(exArgs.server, true))) {

Expand Down
Loading

0 comments on commit 7525652

Please sign in to comment.