Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

public class BasicsPublish {
public static void main(String[] args) {
try (Connection nc = Nats.connect("demo.nats.io")) {
try (Connection nc = Nats.connect("nats://localhost:4222")) {
// NATS-DOC-START
// Publish a message to the subject "weather.updates"
byte[] data = "Temperature: 72°F".getBytes(StandardCharsets.UTF_8);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

public class BasicsSubscribe {
public static void main(String[] args) {
try (Connection nc = Nats.connect("demo.nats.io")) {
try (Connection nc = Nats.connect("nats://localhost:4222")) {
// NATS-DOC-START
// Subscribe to 'weather.updates' synchronously
Subscription sub = nc.subscribe("weather.updates");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public class GettingStartedPublish {
// NATS-DOC-START
public static void main(String[] args) {
try (Connection nc = Nats.connect("demo.nats.io")) {
try (Connection nc = Nats.connect("nats://localhost:4222")) {
// Publish a message to the subject "hello"
byte[] data = "Hello NATS!".getBytes(StandardCharsets.UTF_8);
nc.publish("hello", data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
public class GettingStartedSubscribe {
// NATS-DOC-START
public static void main(String[] args) {
try (Connection nc = Nats.connect("demo.nats.io")) {
try (Connection nc = Nats.connect("nats://localhost:4222")) {
// Asynchronous Subscriber requires a dispatcher
// Dispatchers can be shared
Dispatcher d = nc.createDispatcher(msg -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public class JetStreamBasic {
public static void main(String[] args) {
try (Connection nc = Nats.connect("demo.nats.io")) {
try (Connection nc = Nats.connect("nats://localhost:4222")) {

// NATS-DOC-START
// Create a stream that captures any subject under `orders.`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

public class QueueGroupsBasic {
public static void main(String[] args) {
try (Connection nc = Nats.connect("demo.nats.io")) {
try (Connection nc = Nats.connect("nats://localhost:4222")) {
// NATS-DOC-START
// Worker A
Dispatcher workerA = nc.createDispatcher(msg -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void onMessage(Message msg) throws InterruptedException {
}

public static void main(String[] args) {
try (Connection nc = Nats.connect("demo.nats.io")) {
try (Connection nc = Nats.connect("nats://localhost:4222")) {
List<Worker> workers = new ArrayList<Worker>();

String subject = "tasks";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

public class QueueGroupsMixedSubscribers {
public static void main(String[] args) {
try (Connection nc = Nats.connect("demo.nats.io")) {
try (Connection nc = Nats.connect("nats://localhost:4222")) {

// NATS-DOC-START
// Audit logger - receives all messages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

public class QueueGroupsRequestReply {
public static void main(String[] args) {
try (Connection nc = Nats.connect("demo.nats.io")) {
try (Connection nc = Nats.connect("nats://localhost:4222")) {

// NATS-DOC-START
List<Dispatcher> dispatchers = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

public class RequestReplyBasic {
public static void main(String[] args) {
try (Connection nc = Nats.connect("demo.nats.io")) {
try (Connection nc = Nats.connect("nats://localhost:4222")) {

// NATS-DOC-START
// Set up a service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

public class RequestReplyCalculator {
public static void main(String[] args) {
try (Connection nc = Nats.connect("demo.nats.io")) {
try (Connection nc = Nats.connect("nats://localhost:4222")) {

// NATS-DOC-START
// Calculator service
Expand All @@ -24,11 +24,14 @@ public static void main(String[] args) {
int x = Integer.parseInt(parts[0]);
int y = Integer.parseInt(parts[1]);
nc.publish(msg.getReplyTo(), ("" + (x + y)).getBytes(StandardCharsets.UTF_8));
return;
}
// fall through
}
catch (Exception e) {
// you could make some other reply here
// fall through
}
nc.publish(msg.getReplyTo(), "error: invalid input".getBytes(StandardCharsets.UTF_8));
});
dCalcAdd.subscribe("calc.add");

Expand All @@ -50,6 +53,15 @@ public static void main(String[] args) {
else {
System.out.printf("10 + 7 = %s\n", new String(m.getData()));
}

// Make a request with a timeout and direct response
m = nc.request("calc.add", "10 x".getBytes(StandardCharsets.UTF_8), Duration.ofMillis(500));
if (m == null) {
System.out.println("3) No Response");
}
else {
System.out.printf("10 + x = %s\n", new String(m.getData()));
}
// NATS-DOC-END
}
catch (InterruptedException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

public class RequestReplyHeaders {
public static void main(String[] args) {
try (Connection nc = Nats.connect("demo.nats.io")) {
try (Connection nc = Nats.connect("nats://localhost:4222")) {

// NATS-DOC-START
// Header Aware service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

public class RequestReplyMultipleResponders {
public static void main(String[] args) {
try (Connection nc = Nats.connect("demo.nats.io")) {
try (Connection nc = Nats.connect("nats://localhost:4222")) {

// NATS-DOC-START
// Set up 2 instances of the service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static void main(String[] args) {
// NATS-DOC-START
// You must specify the reportNoResponders() connect option
Options options = Options.builder()
.server("demo.nats.io")
.server("nats://localhost:4222")
.reportNoResponders()
.build();
try (Connection nc = Nats.connect(options)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

public class RequestReplyTimeout {
public static void main(String[] args) {
try (Connection nc = Nats.connect("demo.nats.io")) {
try (Connection nc = Nats.connect("nats://localhost:4222")) {

// NATS-DOC-START
// Make a request expecting a future
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

public class SubjectsMonitoring {
public static void main(String[] args) {
try (Connection nc = Nats.connect("demo.nats.io")) {
try (Connection nc = Nats.connect("nats://localhost:4222")) {

// NATS-DOC-START
// Asynchronous subscribers require a dispatcher
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public class SubjectsMultiWildcard {
// NATS-DOC-START
public static void main(String[] args) {
try (Connection nc = Nats.connect("demo.nats.io")) {
try (Connection nc = Nats.connect("nats://localhost:4222")) {

// NATS-DOC-START
// Subscribe to all alarms
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

public class SubjectsSingleWildcard {
public static void main(String[] args) {
try (Connection nc = Nats.connect("demo.nats.io")) {
try (Connection nc = Nats.connect("nats://localhost:4222")) {

// NATS-DOC-START
// Subscribe to the shipped orders
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ private void testWithWriter(OutputStreamWrite writer, String msgStartsWith) thro
}
}
catch (IllegalStateException ise) {
System.out.println(msgStartsWith + " | " + ise);
assertTrue(ise.getMessage().startsWith(msgStartsWith));
}
try {
Expand Down
Loading