Skip to content

Commit

Permalink
bump version to 3.0
Browse files Browse the repository at this point in the history
- added ErrNotJSMessage
  • Loading branch information
Kazmirchuk committed Dec 23, 2023
1 parent 3b4502c commit 2169eb4
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 10 deletions.
5 changes: 3 additions & 2 deletions JsAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -428,8 +428,9 @@ In addition to all [core NATS errors](CoreAPI.md#error-handling), the `jet_strea
| ErrBucketNotFound | from ErrStreamNotFound | Bucket does not exist |
| ErrMsgNotFound | 404/10037 | Message not found in a stream |
| ErrKeyNotFound | from ErrMsgNotFound | Key not found in a bucket |
| ErrJSResponse | | Other JetStream error. `code` and `err_code` is passed in the Tcl error code and `description` is used for the error message. |

| ErrJSResponse | any| Other JetStream error. `code` and `err_code` is passed in the Tcl error code and `description` is used for the error message. |
| ErrNotJSMessage | N/A | Thrown by [nats::metadata](#natsmetadata-message) when a message didn't come from a consumer |

See also "Error Response" in [ADR-1](https://github.com/nats-io/nats-architecture-and-design/blob/main/adr/ADR-1.md#error-response).

[^1]: You can specify the `-expires` option explicitly (ms), but this is an advanced use case and normally should not be needed.
Expand Down
14 changes: 10 additions & 4 deletions KvAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,19 @@ Returns a KV origin configuration to be used with [create_kv_aggregate](#js-crea
- `-stream str` - in case the origin is not an actual bucket, but a mirror, you need to pass the stream/mirror name as well [^5]
- `-keys list` - optional filter

If the origin bucket is in another JetStream domain or account, you need two more options:
- `-api APIPrefix` (required) - the subject prefix that imports the other account/domain
- `-deliver deliverySubject` (optional) - the delivery subject to use for the push consumer
If the origin bucket is in another JetStream domain:
- `-domain str` - domain name
If the origin bucket is in another account:
- `-api APIPrefix` - the subject prefix that imports the other account

In both cases you can also specify:
- `-deliver deliverySubject` (optional) - the delivery subject to use for the push consumer/KV watcher

*Note*: `-domain` is a shorthand option equivalent to `-api "\$JS.$domain.API"`

Example of creating a writable KV aggregate sourcing a subset `new.>` of keys/values from another bucket `HUB_BUCKET` located in the `hub` domain:
```Tcl
set origin [nats::make_kv_origin -bucket HUB_BUCKET -keys new.> -api "\$JS.hub.API"]
set origin [nats::make_kv_origin -bucket HUB_BUCKET -keys new.> -domain hub]
set kv [$js create_kv_aggregate LEAF_KV true [list $origin] -description "writable filtered KV aggregate"]
```
See also [nats::make_stream_source](JsApi.md#natsmake_stream_source--option-value).
Expand Down
2 changes: 2 additions & 0 deletions examples/kv_mirror.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ set conn_hub [nats::connection new "HUB"]
$conn_hub configure -servers nats://localhost:4222 -user acc -password acc
$conn_hub connect
set js_hub [$conn_hub jet_stream -timeout 1000]
puts "Check JS domain: [dict get [$js_hub account_info] domain]"

puts "Connecting to the 'leaf' NATS..."
set conn_leaf [nats::connection new "LEAF"]
$conn_leaf configure -servers nats://localhost:4111 -user acc -password acc
$conn_leaf connect
set js_leaf [$conn_leaf jet_stream -timeout 1000]
puts "Check JS domain: [dict get [$js_leaf account_info] domain]"

puts "Create a KV bucket in the hub..."
set kv_hub [$js_hub create_kv_bucket HUB_BUCKET -history 64]
Expand Down
5 changes: 4 additions & 1 deletion jet_stream.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -1232,9 +1232,12 @@ proc ::nats::_ns2ms {dict_name args} {
# metadata is encoded in the reply field:
# V1: $JS.ACK.<stream>.<consumer>.<delivered>.<sseq>.<cseq>.<time>.<pending>
# V2: $JS.ACK.<domain>.<account hash>.<stream>.<consumer>.<delivered>.<sseq>.<cseq>.<time>.<pending>.<random token>
# NB! I've got confirmation in Slack that as of Feb 2023, V2 metadata is not implemented yet in NATS
# NB! as of Dec 2023, V2 metadata is not implemented yet in NATS, see nats-server/server/consumer.go: const expectedNumReplyTokens = 9
proc ::nats::metadata {msg} {
set mlist [split [dict get $msg reply] .]
if {[llength $mlist] != 9} {
throw {NATS ErrNotJSMessage} "Message with subject [dict get $msg subject] is not a JetStream message"
}
set mdict [dict create \
stream [lindex $mlist 2] \
consumer [lindex $mlist 3] \
Expand Down
2 changes: 1 addition & 1 deletion nats_client.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,7 @@ oo::class create ::nats::connection {
tls_required $tls_done \
name [json::write string $config(name)] \
lang [json::write string Tcl] \
version [json::write string 2.0.3] \
version [json::write string 3.0] \
protocol 1 \
echo $config(echo)]

Expand Down
4 changes: 2 additions & 2 deletions pkgIndex.tcl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package ifneeded nats 2.0.3 \
package ifneeded nats 3.0 \
[list apply {{dir} {
source [file join $dir nats_client.tcl]
source [file join $dir server_pool.tcl]
source [file join $dir jet_stream.tcl]
source [file join $dir key_value.tcl]
package provide nats 2.0.3
package provide nats 3.0
}} $dir]

0 comments on commit 2169eb4

Please sign in to comment.