Now that Ack can be used by non JetStream subscriptions,
to subscriber directly it is only needed to use a regular
subscription.
Signed-off-by: Waldemar Quevedo <wally@synadia.com>
This adds logic to the client so that some type of consumers can
be cleaned up depending on whether `Unsubscribe` or `Drain` are called:
```go
// Deletes a consumer (both ephemeral and durables)
sub.Unsubscribe()
// Does not delete a durable consumers, but ephemerals are deleted.
sub.Drain()
```
This also means that both `nc.Drain` would also clean up any
ephemeral consumer that was created, but not doing anything
to durable consumers that were created or attached.
This way in case a durable is created and then an application restarts
and reattaches to the same durable consumer, then it can still delete
the consumer that it created with `Unsubscribe` or gracefully close
using `Drain` without deleting durable consumers.
Signed-off-by: Waldemar Quevedo <wally@synadia.com>
This changes some of the internals of how functional options
are used so that it gives more flexibility when growing the number
of options in the client.
The API stays the same but instead of options being concrete types,
PubOpt, SubOpt and JSOpt are interfaces so that the behavior changes
depending on where an option is used.
Signed-off-by: Waldemar Quevedo <wally@synadia.com>
This separates the JetStream interface into two smaller interfaces:
A JetStream interface which is for producing and consuming messages
and a JetStreamManager interface for creating streams/consumers.
This also adds a new interface that is the compound of both called
JetStreamContext and is the one that is being returned when calling
`nc.JetStream()`.
This change allows to opt-in to the behaviors provided by the
JetStreamContext as needed, for example:
```go
// Can be used to produce/consume messages, but not for creating streams
var js nats.JetStream
js, err = nc.JetStream()
// Can be used for managing streams/consumers
var jsm nats.JetStreamManager
js, err = nc.JetStream()
// Can still be used to both create streams and publish
js, err := nc.JetStream()
```
Signed-off-by: Waldemar Quevedo <wally@synadia.com>