Skip to content
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

Acking a by-category stream, doesn' seem to work #37

Closed
askasp opened this issue Apr 29, 2021 · 3 comments · Fixed by #38
Closed

Acking a by-category stream, doesn' seem to work #37

askasp opened this issue Apr 29, 2021 · 3 comments · Fixed by #38
Labels

Comments

@askasp
Copy link

askasp commented Apr 29, 2021

Hey again, I will try to contribute by finding the error myself, but I can post it here in the mean time.

It seems that acking on a persistent subscription on a by-category stream is not working.
:ok = Spear.ack(JaaApiLive.EventStoreDbClient, sub, msg)
evaluates fine, but the event is sent over and over.

My guess is that it is somehow related to the event being a link as it is a projection stream.

@the-mikedavis
Copy link
Collaborator

the-mikedavis commented Apr 29, 2021

ah another nice find! Thanks for trying out spear and finding all my embarrassing bugs 😁

I suspect that this is just like the other problem: the link data that we would need to acknowledge events is probably currently discarded. In this case instead of the .metadata.stream_revision field on a link, I think we need the .id. The event_store.client.persistent_subscriptions.ReadReq.Ack message looks like this: it's pretty thin, just a list of event IDs to acknowledge as a batch. I suspect it needs these event IDs to line up with the ID of the link instead of the resolved event when acknowledging persistent subscriptions.

I'm sure that there's a way that isn't too messy to fix this in the current code-base but I think it's probably wiser for me to bite the bullet of the refactor in #36 (and ideally some real testing in #35) before/during tackling this problem. Right now links are a bit of an after-thought and I'd like to change that.

The day is just getting started here in the CDT timezone, I'll have this fixed in a jiffy!

the-mikedavis added a commit that referenced this issue Apr 29, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
connects #37
@the-mikedavis
Copy link
Collaborator

the-mikedavis commented Apr 29, 2021

Ok so it looks like the .id hypothesis was correct. #38 added a new :link field to t:Spear.Event.t/0 which Spear.ack/3 and Spear.nack/4 now respect and use to source each event's ID. I didn't add any test cases yet for projected streams but I set up a persistent subscription locally in my IEx and ack-ed my way through a category stream and it appears to be working like expected 👍

v0.9.0 is a bit of a breaking change if you're depending on Spear.Event.metadata.link explicitly. Upgrading should be as easy as matching on the :link top-level field instead of that metadata field

# before
def revision(%Spear.Event{metadata: %{link: %{stream_revision: revision}}}), do: revision
def revision(%Spear.Event{metadata: %{stream_revision: revision}}), do: revision

# after
def revision(%Spear.Event{link: %Spear.Event{} = link}), do: revision(link)
def revision(%Spear.Event{metadata: %{stream_revision: revision}}), do: revision

Also if you're looking into using persistent subscriptions, be sure to check out Broadway. It's has a really nice Acknowledger behaviour that fits well with the persistent subscription ack/nack/park system. We recently built a producer for regular and persistent subscriptions. Our producers are a bit experimental and surely has some bugs to iron out but they makes writing event-handling topologies really slick (here's an example handler).

Thanks again for reporting, glad to have you trying out the library! 🙂

@askasp
Copy link
Author

askasp commented Apr 29, 2021

It is my pleasure! And thanks for being so responsive (and insanely productive).

I really liked the thorough explanation. I figured it had to be something regarding resolved id's but I became lost trying to figure out how to fix it 🙈

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants