IntroductionΒΆ

messagebus is a library that implement some Domain Driven Design approach that is popularised by the book Architecture Patterns With Python.

It encourage to create a domain model, by subclassing the class messagebus.Model, and by writing messagebus.Command and messagebus.Event.

messagebus.Model are stored and accessed via repositories. Every models has its own repository, a subclass of messagebus.AsyncAbstractRepository and those repositories are then gather in a Unit Of Work.

Mutations of the models are also part of the domain models, those mutations are store in specific objects, named Command and Event.

Commands are implemented by subclassing the messagebus.Command in order to discribe the intention of the mutation.

Events are implemented by subclassing the messagebus.Event in order to discribe that the mutation has happened.

Commands and events are versionned, the update of any format, that represent a Breaking Change is discouraged without creating a new version.

messagebus.Command and messagebus.Event are both messagebus.Message. And those messages can be listened by a service handler, in a messagebus.AsyncMessageBus using a decorator messagebus.async_listen().

Note

The messagebus.SyncMessageRegistry has to be used with the decorator messagebus.sync_listen() for the synchronous version.

During the startup of the app, all service handlers must be registered the message registry by calling the function messagebus.scan().

Afterwhat, the messagebus.AsyncMessageBus is ready to handle message using it function messagebus.AsyncMessageBus.handle(). you will have understood it, the messagebus.AsyncMessageBus is the message bus object.

Finally, when the unit of work commit its transaction, the a publisher object can send all the desired message to an Event Stream.

This is a bit condensed, but the essence of the event driven throw the message bus, is here. So lets get deeper going step by step in the cookbook.