scaut.EventStoreFsExt

Persistent subscriptions now reconnect automatically.


Keywords
eventstore, eventsourcing, fsharp
License
MIT
Install
Install-Package scaut.EventStoreFsExt -Version 0.1.38

Documentation

EventStoreFsExt (ESFX)

An extension for EventStore to make it easier to use with a F# project. Still unstable. Use at your own risk!

Provides:

  • Automatic event serialization/deserialization
  • Automatic generation of status events
  • Proper wrapping to make it easy to use async workflows.
  • Typesafe streams.

Get it at: https://www.nuget.org/packages/scaut.EventStoreFsExt/

Expects that an eventtype projection is available, so run your event store with something like:

--db ./db --log ./logs --run-projections=all --start-standard-projections=true

Types

ESFX provides it's own typesafe implementation of stream names and a bit extra :)

EventStreams

An EventStream is a representation of a (string) stream in EventStore. A stream segment is constructed with StreamId s where s : string We introduce the +> operator to concatenate two streams together:

let stream = (StreamId "test") +> ("StreamId "stream")
toString stream = "test-stream"

Event<'t>

An ADT which basically wraps a tuble of an event of type 't and a Stream. The t should be a record, else serialization is not guaranteed to work.

SideEffectResult

The result of an event handler which has side effects.

type SideEffectResult =
    | Error of string
    | Success of string

The string is a message indicating status.

If an Error is returned the handler reports fail and if Success is returned it reports acknowledgement.

API

openConnection(settings)

Opens a connection to the EventStore and returns a ESFXConnection object containing methods to operate on the EventStore. Must be passed a settings object with default user credentials set to an admin user, to be able to create and delete persistent subscriptions. Possibly other operations like subscribing to event type streams as well.

Returns an ESFXConnection. The ESFXConnection type contains all of the API.

GetConnection

Returns the underlying IEventStoreConnection object.

ReadEvent

Reads the last event of stream stream.

this.ReadEvent (stream : Stream) : Async<'t option>

Where 't is an inner event type that was serialized.

SendEvent

Sends an event on the stream assocatedStream.

SendEvent (Events.Event (event, associatedStream)) : Async<WriteResult>

SubscribeToStream

Subscribes to a stream stream catching up from an event number. The handler is given the original subscription, the original event and a deserialized event of type 't.

SubscribeToStream<'t>
                (stream : Stream, catchupFrom : System.Nullable<int>, handler : EventStoreCatchUpSubscription -> ResolvedEvent -> 't -> unit) : EventStoreStreamCatchUpSubscription

SubscribeToEventType

Just like SubscribeToStream, except it subscribes to the event of the type that is handled by the handler.

SubscribeToEventType  (catchupFrom : System.Nullable<int>, eventHandler : EventStoreCatchUpSubscription -> ResolvedEvent -> 't -> unit)

CreatePersistentSubscription

Creates a persistent subscription on stream stream with the groupName groupName. The groupName (I think) is unique per stream, so you can have the same group name listening on several streams.

CreatePersistentSubscription (stream : EventStreams.Stream, groupName : string) : Async<unit>

DeletePersistentSubscription

Deletes a persistent subscription.

DeletePersistentSubscription (stream : EventStreams.Stream, groupName : string) : Async<unit>

SubscribePersistent

Subscribes to a persistent subscription (which must be created first, obviously). The handler is given the original event, the deserialized inner event and must return a SideEffectResult indicating whether the event was successfully handled or not.

SubscribePersistent (stream : Stream, eventHandler : (ResolvedEvent * 't) -> Events.SideEffectResult) :  Async<EventStorePersistentSubscriptionBase>

SubscribeToEventTypePersistent

Like SubscribePersistent, but subscribes to an event type stream indicated by the type of the handler.

SubscribeToEventTypePersistent (eventHandler : (ResolvedEvent * 't) -> Events.SideEffectResult)

Semantic versioning

ESFX uses semantic versioning. Still far from a v. 1.0.0 release :) Maintainers: Remember to update the nuspec file version when you want a new version published to nuget.org

Building from source

  1. Clone the repo.
  2. Open solution file in Visual Studio.
  3. Right click solution and restore NuGet packages.
  4. Build all.