In my previous blog post, I talked about Catch-Up Subscriptions in-comparison to Persistent Subscriptions in Event Store. I’ve been meaning to create a little demo as I didn’t find very much in my limited searching. Specifically, I wanted to create a console app that would contain the subscription client and another console app (event writer) that would write events to a stream. This way you could run the subscription client multiple times, then run the event writer and see how the events are only received from one subscription client.
Sponsor: Do you build complex software systems? See how NServiceBus makes it easier to design, build, and manage software systems that use message queues to achieve loose coupling. Get started for free.
SourceAll the source code for this demo is available on GitHub. Please take a look to follow along as the rest of this post is describing how it works. Although I’ve added this to as a new repo on GitHub, It is also available in the EventStore.Samples.DotNet repo on GitHub along with other subscription model examples.
ServerIf you don’t have it already, download a copy of Event Store and run EventStore.ClusterNode.exe with default arguments. This will start the Event Store server under port 1113. The web UI will be accessible via http://localhost:2113
Create SubscriptionFirst you need to create a subscription to a stream. You will also provide a group name which you will also use when connecting to the subscription. In my demo I’ve included code to create the subscription. This is simply because I don’t want anyone running the demo to have to create it manually. The documentation discourages it from being created in your general application code.
Normally the creating of the subscription group is not done in your general executable code. Instead it is normally done as a step during an install or as an admin task when setting things up. You should assume the subscription exists in your code.The web UI has a pretty nice interface for viewing your subscriptions as well as creating and updating them.
4 thoughts to “Event Store Persistent Subscriptions Demo”
But then how do I run a catch-up/replay for when I add new projections, etc?
You would simply create a new group on an existing stream. The new group would have a “current” position of 0. Once you connect to that stream under the new group, you would start processing from the first event.