Can now attach a context to a subscription so that it is
unsubscribed and/or consumer deleted via propagation of
cancellation via parent context.
Signed-off-by: Waldemar Quevedo <wally@synadia.com>
If user creates an ordered consumer and uses AutoUnsubscribe()
with the returned subscription, and if the ordered consumer was
reset (due to a gap detection), the library should resend an
UNSUB with adjusted max for the new subscription ID.
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
Also:
- Fixed message reply in PublishMsgAsync
- Ability to seal streams
- Ability for consumer to get message headers only, no msg payload
- GetLastMsg and purgeStream by subject
Signed-off-by: Derek Collison <derek@nats.io>
When calling `js.QueueSubscribe[Sync](subject, queue_name)`, if
no durable name is provided, the queue name is used as the durable
name, so the same restriction applies
Resolves#840
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
The deadline of a context is now used to calculate
the time used for `expires` instead of the default `ttl`
of the JetStream context which was 5s. This was preventing
library users from passing a context with a custom timeout.
This also disallows the usage of `context.Background`
to make it explicit that `sub.Fetch` has to be used
with a context that has a timeout since each fetch
request has to include an expire time anyway.
In case `context.WithCancel` is used, then a child context
with the same duration as the JetStream context default
timeout will be created.
Also in case msg.Ack it was possible to pass both timeout
and a context which would have been ambiguous and only
context option being used.
Signed-off-by: Waldemar Quevedo <wally@synadia.com>
Copied the go doc from implementation to interface, and reworded
some sections.
I decided to copy versus move because some IDE (for instance VS code)
seem to show the doc (when hovering) from the implementation, not
the interface.
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
This would happen when pull requests would have filled the waiting
queue in the JetStream consumer and a 408 status was returned.
Resolves#809
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
This is done to alert the user that consumer config is not changed
as one would expect.
This change is more tricky than expected. We can't simply compare
user's consumer config with what is returned from the server.
For once, there are configurations that may not be set by the
user that were set when the consumer was created, that the lib
should not fail. Let's say the consumer is created with a description,
why fail the user if they don't pass the Description() option at all?
The Description() option was actually missing, but this is a good
example. But same could be say with for instance "optional start
sequence". This may be something that is set when the consumer
is first created (possibly outside of the app with CLI), but when
user calls js.Subscribe(), that option should not have to be
set to the value that was used when creating the consumer.
I had to add "not set" values for replay and deliver policy, similar
to ack policy.
I added an extensive test that checks proper error when trying
to make configuration changes, but also that if the options are
not set, then the lib does not fail the subscribe call.
Resolves#796
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
A new object `SequenceInfo` is added for `Delivered` and `AckFloor`'s
`ConsumerInfo` fields. This object contains `Last` which represents
the last activity time (in UTC).
Having this field under `SequencePair` was wrong since we used
`SequencePair` in other object, namely `MsgMetadata`, and in
that context, `Last` did not make sense.
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
This is to align with newer version of the ADR describing the
subscription workflow:
- Removed option SubjectIsDelivery that was introduced in main branch
(but not released yet).
- Take into consideration the new ACK layout
- Make sure that OrderedConsumer rejects user configuring DeliverSubject
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
As discussed with Matthias who came up with the idea, this is
better because then we make use of the provided subject. Otherwise
it was looking weird to have something which meaning was:
```
js.SubscribeSync("ignored", nats.BindDeliverSubject("p.d4"))
```
Instead you would now have:
```
sub, err = js.SubscribeSync("p.d4", nats.SubjectIsDelivery())
```
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
They will be described in the release notes, but gist:
Added:
- `DeliverSubject()` option to configure the deliver subject of a JetStream consumer created by the `js.Subscribe()` call (and variants)
- `BindDeliverSubject()` option to subscribe directly to a JetStream consumer deliver subject (bypassing any lookup or JetStream consumer creation)
- Fields `DeliverGroup` in `ConsumerConfig`, `PushBound` in `ConsumerInfo`. They help making prevent incorrect subscriptions to JetStream consumers
- Field `Last` in `SequencePair`
Changed:
- With a `PullSubscription`, calling `NextMsg()` or `NextMsgWithContext()` will now return `ErrTypeSubscription`. You must use the `Fetch()` API
- If the library created internally a JetStream consumer, the consumer will be deleted on `Unsubscribe()` or when the `Drain()` completes
- Fail multiple instances of a subscription on the same durable push consumer (only one active at a time). Also, consumers now have the concept of `DeliverGroup`, which is the queue group name they are created for. Only queue member from the same group can attach to this consumer, and a non queue subscription cannot attach to it. Note that this requires server v2.3.5
- Attempting to create a queue subscription with a consumer configuration that has idle heartbeats and/or flow control will now result in an error
Fixed:
- Possible lock inversion
- JetStream consumers could be incorrectly deleted on subscription's `Unsubscribe()`
Resolves#785Resolves#776Resolves#775Resolves#748Resolves#747
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
Use a SyncSubscription instead. The only visible change from the
user is that calling Fetch() after Unsubscribe() returns ErrBadSubscription
instead of timeout or context deadline exceeded, which makes more
sense to me. This is the only test that I had to tweak.
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
This introduces ordered consumers. They are a convenience over ephemeral, no ack, no redelivery, only deliver things in strict order setups.
We have the swap out when we detect gaps and change out the underlying sub and JetStream consumer, and we process the heartbeats as well, detecting gaps at the end or if a stream or consumer is pulled out from underneath of us.
Signed-off-by: Derek Collison <derek@nats.io>
Also added missing subscription's lock when setting some fields
at the end of initialization.
Fixed some flappers and missing defers.
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>