diff --git a/SUMMARY.md b/SUMMARY.md index e5e30a1..5a3a49c 100644 --- a/SUMMARY.md +++ b/SUMMARY.md @@ -46,10 +46,12 @@ ## Developing With NATS * [Concepts](developer/concepts/intro.md) + * [Subject-Based Messaging](developer/concepts/subjects.md) * [Publish-Subscribe](developer/concepts/pubsub.md) * [Request-Reply](developer/concepts/reqreply.md) - * [Using Queues to Share Work](developer/concepts/queue.md) - * [Subject-Based Messaging](developer/concepts/subjects.md) + * [Queue Groups](developer/concepts/queue.md) + * [Acknowledgements](developer/concepts/acks.md) + * [Sequence Numbers](developer/concepts/seq_num.md) * [Connecting](developer/connecting/intro.md) * [Connecting to the Default Server](developer/connecting/default_server.md) diff --git a/developer/concepts/acks.md b/developer/concepts/acks.md new file mode 100644 index 0000000..fe5ff27 --- /dev/null +++ b/developer/concepts/acks.md @@ -0,0 +1,31 @@ +# Acknowledgements + +In a system with at-most-once semantics, there are times when messages are lost. If your application is doing request-reply then it can simply use timeouts to handle network and application failures. When you are using one-way messaging the easiest way to insure message delivery is to turn it into a request-reply with the concept of an acknowledgement message, or ACKS. In NATS an ACK can simply be an empty message, a message with no body. + +
+digraph nats_request_reply {
+ rankdir=LR
+
+ subgraph {
+ publisher [shape=box, style="rounded", label="Publisher"];
+ }
+
+ subgraph {
+ subject [shape=circle, label="Subject"];
+ reply [shape=circle, label="Reply"];
+ {rank = same subject reply}
+ }
+
+ subgraph {
+ sub1[shape=box, style="rounded", label="Subscriber"];
+ }
+
+ publisher -> subject [label="msg1"];
+ publisher -> reply [style="invis", weight=2];
+ subject -> sub1 [label="msg1"];
+ sub1 -> reply [label="ack"];
+ reply -> publisher;
+}
+
graph nats {
@@ -17,8 +19,4 @@ graph nats {
}
digraph nats_pub_sub {
diff --git a/developer/concepts/queue.md b/developer/concepts/queue.md
index e5617f1..7331ef2 100644
--- a/developer/concepts/queue.md
+++ b/developer/concepts/queue.md
@@ -4,6 +4,8 @@ NATS provides a load balancing feature called queue subscriptions. Using queue s
To create a queue subscription, subscribers register a queue name. All subscribers with the same queue name form the queue group. As messages on the registered subject are published, one member of the group is chosen randomly to receive the message. Although queue groups have multiple subscribers, each message is consumed by only one.
+One of the great features of NATS is that queue groups are defined by the subscribers, not on the server. Applications can create new queue groups without any server change.
+
Queue subscribers are ideal for auto scaling as you can add or remove them anytime, without any configuration changes or restarting the server or clients.
diff --git a/developer/concepts/reqreply.md b/developer/concepts/reqreply.md
index b26ea39..e9f3ac9 100644
--- a/developer/concepts/reqreply.md
+++ b/developer/concepts/reqreply.md
@@ -1,6 +1,6 @@
-# Request Reply
+# Request-Reply and Scatter-Gather
-NATS supports two flavors of request reply messaging: point-to-point or one-to-many. Point-to-point involves the fastest or first to respond. In a one-to-many exchange, you can set a limit on the number of responses the requestor may receive or use a timeout to limit on the speed of the response.
+NATS supports two flavors of request reply messaging: point-to-point or one-to-many. Point-to-point involves the fastest or first to respond. In a one-to-many exchange, you can set a limit on the number of responses the requestor may receive or use a timeout to limit on the speed of the response. One-to-many request reply is sometimes called *scatter gather*.
In a request-response exchange the publish request operation publishes a message with a reply subject expecting a response on that reply subject. Many libraries allow you to use a function that will automatically wait for a response with a timeout. You can also handle that waiting process yourself.
diff --git a/developer/concepts/seq_num.md b/developer/concepts/seq_num.md
new file mode 100644
index 0000000..81501c9
--- /dev/null
+++ b/developer/concepts/seq_num.md
@@ -0,0 +1,25 @@
+# Sequence Numbers
+
+A common problem for one-to-many messages is that a message can get lost or dropped due to a network failure. A simple pattern for resolving this situation is to include a sequence id with the message. Receivers can check the sequence id to see if they miss anything.
+
+
+digraph nats_pub_sub {
+ rankdir=LR
+ publisher [shape=box, style="rounded", label="Publisher"];
+ subject [shape=circle, label="Subject"];
+ sub [shape=box, style="rounded", label="Subscriber"];
+
+ publisher -> subject [label="updates.1"];
+ publisher -> subject [label="updates.2"];
+ publisher -> subject [label="updates.3"];
+
+ subject -> sub [label="updates.*"];
+}
+
+
+In order to really leverage sequence ids there are a few things to keep in mind:
+
+* Each sender will have to use their own sequence
+* If possible, receivers should be able to ask for missing messages by id
+
+With NATS you can embed sequence ids in the message, or you can include them in the subject. For example, a sender can send messages to `updates.1`, `updates.2`, etc... and the subscribers can listen to `updates.*` and optionally parse the subject to determine the sequence id.
\ No newline at end of file
diff --git a/developer/concepts/subjects.md b/developer/concepts/subjects.md
index 1c4323e..1fe94f0 100644
--- a/developer/concepts/subjects.md
+++ b/developer/concepts/subjects.md
@@ -73,3 +73,7 @@ digraph g {
subject -> sub3 [label="msg"];
}
+
+### Monitoring and Wire Taps
+
+Subject to your security configuration, wildcards can be used for monitoring by creating something sometimes called a *wire tap*. In the simplest case you can create a subscriber for `>`. This application will receive all messages, again subject to security settings, sent on your NATS cluster.
\ No newline at end of file