-
Notifications
You must be signed in to change notification settings - Fork 708
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
New jetstream interface, consumer.Info() returns error consumer instance not yet created #1305
Comments
This issue should only be present when using Aside from this, what info from ordered consumer do you need? Bear in mind that as ordered consumers are managed by the library, while you certainly can ask for info about the currently existing consumer, that consumer instance may be removed at any point and re-created with different name. For some use cases, getting |
@piotrpio thank you! I think it's quite okay with a lazy creation if the first call to using the new consumer consumer can block until the creation is done and the answer can be given. I assume that it (at least logically) if an iterator or .Consume was called before the consumer where ready. So maybe that is also an option to gain a fast return on the create request Actually the answer to your question is lazy load ;) The Metadata call cannot tell me how many messages existed (qualified by the filters) when we started since they will show a moving target. And if the inflow (for some reason) match the speed we can consume, we will, for a period, not reach 0 pending in the .Metadata() info. I haven't tested what is most effective, maybe I need to redesign to create a normal consumer, ask how many messages i already have pending, fetch them in batch, process them and then start a new ordered consumer. But my gut feeling is that ordered consumer will be just as fast and with less complexity and fewer resources created and deleted. So getting this "number of messages to consider loaded" before processing felt the easiest way to do it. I could grab a number that is probably as correct from the metadata of the first message, it just messes up the code . At the moment it's reasonably readable.
Setting the number of msgs to loaded after first msg breaks the flow of my code with some code that is only relevant for the first of maybe many msgs to process. Hope it makes sense. I understand that it is an extra roundtrip and if the ambition with the new simpler interface should be simpler to implement instead of simpler to use, i withdraw my opinion. |
Thanks for the explanation! We changed the code to not return until consumer is created. When it comes to performance, Ordered Consumer is the fasted one. New API goal was to make simple things simple, and hard, possible with clean and nice API. Without magic under the hood that was confusing (like the Hope that clears things out. Ah, and yes, |
Tried with CachedInfo(), works fine. Maybe some updates to the doc+ |
This is not working (testing with nats.go ver v1.27.1) @Jarema |
@tpihl could you elaborate? Which part is not working, are you trying with |
Hi @piotrpio I tried both, CachedInfo() panics and Info() returns the error. go.mod references
Here is the full Test including output ; func Test_VerifyInfoForOrderedConsumer(t *testing.T) {
nc, err := nats.Connect(RedactedNatsURL,
nats.UserInfo(RedactedNatsUser, RedactedNatsPassword),
)
if err != nil {
t.Fatal(err)
}
js, err := jetstream.New(nc)
if err != nil {
t.Fatal(err)
}
str, err := js.Stream(context.TODO(), RedactedStreamName)
if err != nil {
t.Fatal(err)
}
con, err := str.OrderedConsumer(
context.TODO(),
jetstream.OrderedConsumerConfig{
FilterSubjects: []string{
RedactedFilter,
},
},
)
if err != nil {
t.Fatal(err)
}
ci, err := con.Info(context.TODO())
if err != nil {
t.Error(err)
} else {
t.Log(ci.NumPending)
return
}
ci = con.CachedInfo() // this is the statement that throws the panic
t.Log(ci.NumPending)
}
/* Result after executing go test -v for this test only
=== RUN Test_VerifyInfoForOrderedConsumer
x_test.go:217: nats: consumer instance not yet created
--- FAIL: Test_VerifyInfoForOrderedConsumer (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
... (the rest of the output is irrelevant)
*/ |
While that was surprising at first, the reason is pretty simple. #1317 was not part of release v1.27.1! So you'll have to be a bit more patient with this, the next release is coming very soon. You can run your test on against |
Defect
There is no way to know when the consumer actually is created to successfully get info from it. Regardless, calling Info(ctx) on the returned consumer should wait until the consumer is created and then return the info. Returning the error as currently may be factually correct but not useful. An error that it was deleted, thats fine. But the nil error and returned consumer from the OrderedConsumer cannot be used must be a bug.
Versions of
nats.go
and thenats-server
if one was involved:nats.go v1.26.0
nats-server v2.9.17
OS/Container environment:
linux
Steps or code to reproduce the issue:
the call con.Info() returned error;
nats: consumer instance not yet created
Expected result:
Information about the consumer and a nil errror
Actual result:
No information about consumer and an error that the consumer returned by the previous call cannot be used and no way except iterative re-try to continue (and iterative retry is a mess for readable code)
The text was updated successfully, but these errors were encountered: