Skip to content
A Golang reference implementation of the CQRS pattern.
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples/simplecqrs
internal/uuid
LICENSE.md Added comments further comments to dispatcher Jun 5, 2016
README.md Merge pull request #5 from tugberkugurlu/patch-1 Feb 6, 2019
aggregate.go
aggregate_test.go Added simple cqrs example code Aug 12, 2016
aggregatefactory.go
aggregatefactory_test.go
command.go
command_test.go Refactored to work with latest go.geteventstore Aug 8, 2016
commandhandler.go
commandhandler_test.go
dispatcher.go
dispatcher_test.go
errors.go Added simple cqrs example code Aug 12, 2016
event.go
event_test.go
eventbus.go
eventbus_test.go
eventfactory.go Refactored to work with latest go.geteventstore Aug 8, 2016
eventfactory_test.go
eventhandler.go Refactored to work with latest go.geteventstore Aug 8, 2016
eventhandler_test.go Refactored to work with latest go.geteventstore Aug 8, 2016
repository.go Added simple cqrs example code Aug 12, 2016
repository_test.go Added simple cqrs example code Aug 12, 2016
streamnamer.go Refactored to work with latest go.geteventstore Aug 8, 2016
streamnamer_test.go
ycq.go Added simple cqrs example code Aug 12, 2016
ycq_test.go

README.md

Go.CQRS license Go Report Card GoDoc

A Golang CQRS Reference implementation

Go.CQRS provides interfaces and implementations to support a CQRS implementation in Golang. The examples directory contains a sample application that demonstrates how to use Go.CQRS.

As much as possible Go.CQRS has been designed with the principles of CQRS espoused by Greg Young which represents the best thinking on the topic.

CQRS Pattern vs CQRS Framework

CQRS is an architectural pattern. When implementing the CQRS pattern, it is easy to imagine how the code could be packaged into a framework. However, it is recommended that those working with CQRS focus on learning the underlying detail of the pattern rather than simply use a framework.

The implementation of the CQRS pattern is not especially difficult, however it is a steep learning curve because the pattern is very different to the traditional non CQRS architecture. Topics such as Aggregate Design are very different. If you are going to use EventSourcing and eventual consistency then there is a lot of learning to be done.

If you are new to CQRS or simply interested in best practices there is a great 6 hour video of a hands-on CQRS workshop by Greg Young.

Once the pattern is understood, implementations such as Go.CQRS can be used as a reference for learning how to implement the pattern in Golang and also as a foundation upon which to build your CQRS implementation.

What does Go.CQRS provide?

Feature Description
Aggregate AggregateRoot interface and Aggregate base type that can be embedded in your own types to provide common functions required by aggregates
Event An Event interface and an EventDescriptor which is a message envelope for events. Events in Go.CQRS are simply plain Go structs and there are no magic strings to describe them as is the case in some other Go implementations.
Command A Command interface and an CommandDescriptor which is a message envelope for commands. Commands in Go.CQRS are simply plain Go structs and there are no magic strings to describe them as is the case in some other Go implementations.
CommandHandler Interface and base functionality for chaining command handlers
Dispatcher Dispatcher interface and an in memory dispatcher implementation
EventBus EventBus interface and in memory implementation
EventHandler EventHandler interface
Repository Repository interface and an implementation of the CommonDomain repository that persists events in GetEventStore. While there are many generic event store implementations over common databases such as MongoDB, GetEventStore is a specialised EventSourcing database that is open source, performant and reflects the best thinking on the topic from a highly experienced team in this field.
StreamNamer A StreamNamer interface and a DelegateStreamNamer implementation that supports the use of functions with the signiature func(string, string) string to provide flexibility around stream naming. A common way to construct a stream name might be to use the name of your BoundedContext suffixed with an AggregateID.

All implementations are easily replaced to suit your particular requirements.

Example code

The examples folder contains a simple and clear example of how to use go.cqrs to contruct your service. The example is a port of the classic reference implementation m-r by Greg Young.

Getting Started

    $ go get github.com/jetbasrawi/go.cqrs

Refer to the example application for guidance on how to use Go.CQRS.

You can’t perform that action at this time.