Skip to content

Commit

Permalink
fix: add stream fields allow_direct and mirror_direct
Browse files Browse the repository at this point in the history
When updating a stream that has `allow_direct` stream
set to `true` will overwrite it within the server to `false`.
  • Loading branch information
Daniel Carpenter authored and mmmries committed Jun 24, 2024
1 parent 297ae7b commit 3df7739
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lib/gnat/jetstream/api/stream.ex
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ defmodule Gnat.Jetstream.API.Stream do
Stream struct fields explanation:
* `:allow_direct` - Allow higher performance, direct access to get individual messages. E.g. KeyValue
* `:allow_rollup_hdrs` - allows the use of the Nats-Rollup header to replace all contents of a stream,
or subject in a stream, with a single new message.
* `:deny_delete` - restricts the ability to delete messages from a stream via the API. Cannot be changed
Expand All @@ -35,6 +36,7 @@ defmodule Gnat.Jetstream.API.Stream do
new messages if the Stream exceeds this number of messages
* `:mirror` - maintains a 1:1 mirror of another stream with name matching this property. When a mirror
is configured subjects and sources must be empty.
* `:mirror_direct` - Allow higher performance and unified direct access for mirrors as well.
* `:name` - a name for the Stream.
See [naming](https://docs.nats.io/running-a-nats-service/nats_admin/jetstream_admin/naming).
* `:no_ack` - disables acknowledging messages that are received by the Stream.
Expand Down Expand Up @@ -73,6 +75,7 @@ defmodule Gnat.Jetstream.API.Stream do
:sources,
:subjects,
:template_owner,
allow_direct: false,
allow_rollup_hdrs: false,
deny_delete: false,
deny_purge: false,
Expand All @@ -84,6 +87,7 @@ defmodule Gnat.Jetstream.API.Stream do
max_msg_size: -1,
max_msgs_per_subject: -1,
max_msgs: -1,
mirror_direct: false,
num_replicas: 1,
retention: :limits,
sealed: false,
Expand All @@ -98,6 +102,7 @@ defmodule Gnat.Jetstream.API.Stream do
}

@type t :: %__MODULE__{
allow_direct: boolean(),
allow_rollup_hdrs: boolean(),
deny_delete: boolean(),
deny_purge: boolean(),
Expand All @@ -112,6 +117,7 @@ defmodule Gnat.Jetstream.API.Stream do
max_msgs: integer(),
max_msgs_per_subject: integer(),
mirror: nil | source(),
mirror_direct: boolean(),
name: binary(),
no_ack: nil | boolean(),
num_replicas: pos_integer(),
Expand Down Expand Up @@ -408,10 +414,11 @@ defmodule Gnat.Jetstream.API.Stream do
# Recent versions of NATS sometimes return `"streams": null` in their JSON payload to indicate
# that no streams are defined. But, that would mean callers have to handle both `nil` and a list, so
# we coerce that to an empty list to represent no streams being defined.
streams = case Map.get(decoded, "streams") do
nil -> []
names when is_list(names) -> names
end
streams =
case Map.get(decoded, "streams") do
nil -> []
names when is_list(names) -> names
end

result = %{
limit: Map.get(decoded, "limit"),
Expand Down Expand Up @@ -494,9 +501,11 @@ defmodule Gnat.Jetstream.API.Stream do
template_owner: Map.get(stream, "template_owner")
}
# Check for fields added in NATS versions higher than 2.2.0
|> put_if_exist(:allow_direct, stream, "allow_direct")
|> put_if_exist(:allow_rollup_hdrs, stream, "allow_rollup_hdrs")
|> put_if_exist(:deny_delete, stream, "deny_delete")
|> put_if_exist(:deny_purge, stream, "deny_purge")
|> put_if_exist(:mirror_direct, stream, "mirror_direct")
|> put_if_exist(:sealed, stream, "sealed")
end

Expand Down

0 comments on commit 3df7739

Please sign in to comment.