New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Consumers with Multiple Filters ADR-34 #192
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@scottf not quite sure - supporting it on consumer creation from the JSM-type APIs if the server is older it won't see the fields, and the user would not get an error, so you would need to verify that field against a server version. Previously I wouldn't implement any changes to |
Checking the version of the server you are connected to is not an answer. It does not tell you what the version of the JetStream server otherside of the world is. |
@scottf That's a good point. The problem I see though is if client is new, but server is old. Checking against server version would not help much, as @ripienaar pointed out. Ugly, but functional workaround for backwards compatibility would be to put some reserver word that is not a proper subject filter into EDIT it would be really nice to have JetStream protocol version ;). |
|
@ripienaar was thinking about that as an alternative. |
@scottf Subscribing to Consumer should be fine. example config: "name": "multi-consumer",
"filter_subject": "",
"filter_subjects": ["events", "data"] so you can subscribe with (pseudocode)
So the inconvinience for non-simplified API is:
I would avoid adding a method to subscribe to multiple Subjects, as we're close to releasing simplification betas.
So let's don't do that :). |
I have the implementation for JavaScript - a couple of observations:
|
3. Only one of `FilterSubject` or `FilterSubjects` can be passed. Passing both results in an error (10134) | ||
|
||
4. Until future improvements, only old JS API for consumer creation can be used (the one without `FilterSubject`) in consumer create request. Using new API will yield an error (10135). | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$JS..CONSUMER.CREATE.>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More importantly, if it is an update, the consumer could have been created using the new API, so it could have a name
, depending on how the client is handling this it may reject the name
. Effectively, if Array.isArray(config.filter_subjects)
, it should use the old API. Server will properly catch if filter_subject
and filter_subjects` are both set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we prevent a consumer update from switching between FilterSubjet and FilterSubjects?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No.
User can switch the consumer from being single-filtered to multi-filtered.
Considering above, we might want to deny it until we land solution for multiple filters and new API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - we should put a hint on what the new API is.
3. Only one of `FilterSubject` or `FilterSubjects` can be passed. Passing both results in an error (10134) | ||
|
||
4. Until future improvements, only old JS API for consumer creation can be used (the one without `FilterSubject`) in consumer create request. Using new API will yield an error (10135). | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More importantly, if it is an update, the consumer could have been created using the new API, so it could have a name
, depending on how the client is handling this it may reject the name
. Effectively, if Array.isArray(config.filter_subjects)
, it should use the old API. Server will properly catch if filter_subject
and filter_subjects` are both set.
66bd68e
to
d695461
Compare
Signed-off-by: Tomasz Pietrek <tomasz@nats.io>
Signed-off-by: Tomasz Pietrek <tomasz@nats.io>
Signed-off-by: Tomasz Pietrek <tomasz@nats.io>
9d5f9da
to
4f975ef
Compare
Does there need to be an ADR for the clients to add this field? |
Cant see why that would be needed, we tend to open an issue referencing this one. If there's a ADR that covers the full client design that might need an update. |
Sorry, I meant an issue in this repo that creates a checklist of clients to implement. |
would need that yes |
Ok created #196 |
Title JetStream Consumers Multiple Filters
Context and Problem Statement
Initially, JetStream Consumers could have only one Filter Subject.
As the number of feature requests to specify multiple subjects increased, this feature was added.
That could also reduce the number of Consumers in general.
Context
Server PR: nats-io/nats-server#3500
Design
Client side considerations
To implement the feature without any breaking changes, a new field should be added to Consumer config, both on the server and the clients.
The new field is:
FilterSubjects []string json:"filter_subjects"
Subjects can't overlap each other and have to fit the interest of the Stream.
In case of overlapping subjects, error (10136) will be returned.
Only one of
FilterSubject
orFilterSubjects
can be passed. Passing both results in an error (10134)Until future improvements, only old JS API for consumer creation can be used (the one without
FilterSubject
) in consumer create request. Using new API will yield an error (10135).Each client, to support this feature, needs to add a new field that Marshals into a json array of strings.
Example
Client should add new errors to return them in client language idiomatic fashion.
Server side
To make this change possible and reasonable peformant, server will have a buffer of first message for each subject filtered and will deliver them in order. After delivering message for a subject, buffer for that subject will be filled again, resulting in close to no overhead after the initial buffer fill.
This can be optimized but will not affect API.
Signed-off-by: Tomasz Pietrek tomasz@nats.io