Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
Doc
 
 
 
 
Src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Message Storage

MessageStorage is a library prepared to be used in projects that want to apply the Outbox design pattern.

Platform Status
Travis Travis
GitHub .github/workflows/github.yml
NuGet Package Name Version
MessageStorage.AspNetCore Nuget
MessageStorage.SqlServer Nuget
MessageStorage.SqlServer.DependencyInjection Nuget
MessageStorage.Postgres Nuget
MessageStorage.Postgres.DependencyInjection Nuget
MessageStorage.Integration.MassTransit Nuget

Structure Overview

message-storage structure overview

Getting Started

You can download the MessageStorage.SqlServer.DependencyInjection or MessageStorage.Postgres.DependencyInjection package according to the storage environment you will use.

UseSqlServer / UsePostgres method lets you introduce SqlServer or Postgres is used for system's data storage.

Register method lets you introduce MessageHandlers that is used. When the message is recorded, the tasks that will be executed in the background will be introduced through these classes.

AddMessageStoragePrerequisiteExecutor method lets you execute a predefined prerequisites like db migrations.

AddMessageStorageJobProcessorHostedService method lets you introduce a predefined background service to the system. This service fetches tasks from db and executes.

Sample Startup

services.AddMessageStorage(configurator =>
{
   configurator.UseSqlServer("SqlServerConnectionString");
   configurator.Register(messageHandlerAssemblies);
})
// order is important
.AddMessageStoragePrerequisiteExecutor()
.AddMessageStorageJobDispatcher();

After these steps, you can use the object that is an implementation of IMessageStorageClient interface.

Sample Service

Example of registering SomeEntity and saving SomeEntityCreatedEvent message in the same transaction.

using (IDbConnection connection = _connectionFactory.CreateConnection())
{
    using IDbTransaction dbTransaction = connection.BeginTransaction(IsolationLevel.ReadCommitted);
    await connection.ExecuteAsync( sqlCommandText, sqlCommandParameters, dbTransaction);

    SomeEntityCreated someEntityCreated = new (someEntity.Id, someEntity.SomeProperty, someEntity.CreatedOn); 
    await _messageStorageClient.AddMessageAsync(someEntityCreated, dbTransaction);

    dbTransaction.Commit();
}