nats-io / natscli

The NATS Command Line Interface
Apache License 2.0
453 stars 94 forks source link

sub AckPolicy and description #1070

Closed roeschter closed 1 month ago

roeschter commented 1 month ago

Improved description. Added support for ackPolicy

ripienaar commented 1 month ago
diff --git a/cli/sub_command.go b/cli/sub_command.go
index 98c59d6..0f99f93 100644
--- a/cli/sub_command.go
+++ b/cli/sub_command.go
@@ -451,7 +451,10 @@ func (c *subCmd) subscribe(p *fisk.ParseContext) error {
            }
            subs = append(subs, sub)
        } else {
-           c.jsAck = false
+           if c.jsAck {
+               opts = append(opts, nats.AckExplicit())
+           }
+
            sub, err := js.Subscribe(c.firstSubject(), handler, opts...)
            if err != nil {
                return err

is enough to make this work imo. When accessing a WQ it will error by default

$ nats sub --stream WQ
nats: error: nats: workqueue stream requires explicit ack

and then you pass --ack to make it work, I like the error since ack on a WQ is destructive and so I prefer people opt into that behaviour explicitely.

ripienaar commented 1 month ago

Also worth noting it also doesnt work if there's a consumer on the WQ since there would be overlap. Personally I think not working against WQ is a feature - too easy to destroy all messages in the WQ with a simple fat finger.

roeschter commented 1 month ago

Will not implement those changes, could accidentally delete QueuePolicy content. Adding to help for the time being