Namely for pull consumers: ability to override the replica count or storage type:
```
// Generally inherited by parent stream and other markers, now can be configured directly.
Replicas int `json:"num_replicas"`
// Force memory storage.
MemoryStorage bool `json:"mem_storage,omitempty"`
```
For the stream, this new StreamConfig option:
```
// Allow republish of the message after being sequenced and stored.
RePublish *SubjectMapping `json:"republish,omitempty"`
```
Where SubjectMapping is:
```
// SubjectMapping allows a source subject to be mapped to a destination subject for republishing.
type SubjectMapping struct {
Source string `json:"src,omitempty"`
Destination string `json:"dest"`
}
```
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
Fix a spelling mistake which made it through to go docs.
gospel 1.13.0 is now out, and it added features which let us remove some old
words (eg, pluralizations of types we define), but it also errored out on
seeing a comment in .words which used to be acceptable.
So remove comments from .words and introduce .words.readme instead.
We lose the section-introducer comments. Which is a shame.
This allows for differentiating between the zero value and whether it was intentionally
set to a sequence of zero.
Signed-off-by: Byron Ruth <b@devel.io>
When calling js.Subscribe() (or equivalent) and the library ended-up
creating the JS consumer, a MaxAckPending was set to a very high
value in some cases. We now let the server pick the default if the
value is not explicitly set by the user.
The NATS subscription pending limits are set in a way to ensure
that the subscription can store at least the max ack pending value.
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
Relying on ConsumerInfo.NumPending on create was not realiable
if the NATS subscription exists before (which is normal case)
due to a design in the server that process the add consumer
request and then computes the consumer info (after the consumer
is setup which means it could start to deliver messages).
Changed a bit so that we add a JS consumer without attached
subscription and use internal option to allow a js.Subscribe()
with a bind to existing consumer.
Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
1. If the underlying stream was very busy pending might not go to zero, so snapshot and mark initial state done when received >= init pending or delta == 0
2. When a watcher was cancelled with a context we would not signal to allow and range w.Updates() calls to exit.
3. General flow control checks were timing sensitive after the initial checks, needed to be 2x HB interval always, not just beginning.
Signed-off-by: Derek Collison <derek@nats.io>
The new `gospel` tool, <https://github.com/kortschak/gospel>, uses hunspell
libraries but pre-registers as acceptable words every symbol from the Go
source, massively reducing the noise and making comment spell-checking a
tractable problem. It recently gained support for a `.words` file located in
the same directory as the `go.mod` file, to define local words. With this, we
can fix real issues too.
This PR reduces the complaints down to 4:
1. A reference to `syncSubscribers` which I can't figure out
2. A reference to a `pubArg`
3. Two references to `splitArgs`.
I made two actual code changes:
1. Fixing a **non-exported** const type for consistency with all the others:
`apiStreamList` -> `apiStreamListT`.
2. Changing an error message to refer to a field which exist
Lots of typo fixes; references to since-renamed fields; etc.
A reference to `PublishAsynMsg` might have been intended to be
`PublishAsyncMsg` but that doesn't exist either, so I removed it.
Similarly, `SubjectIsDelivery` lived briefly but a stale reference was left in
a comment, so I removed that.
To reproduce:
go install github.com/kortschak/gospel@latest
gospel .
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>