Skip to content

Commit

Permalink
Support for UUIDv7 values
Browse files Browse the repository at this point in the history
Signed-off-by: Tomasz Maruszak <[email protected]>
  • Loading branch information
zarusz committed Oct 11, 2024
1 parent c2cbd1f commit eb6bd33
Show file tree
Hide file tree
Showing 82 changed files with 646 additions and 369 deletions.
7 changes: 1 addition & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ jobs:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
steps:
# - name: Dump GitHub context
# env:
# GITHUB_CONTEXT: ${{ toJson(github) }}
# run: echo "$GITHUB_CONTEXT"

- name: PR - Checkout
if: github.event_name == 'pull_request_target'
uses: actions/checkout@v3
Expand Down Expand Up @@ -195,7 +190,7 @@ jobs:
name: .NET Tests
path: ./test-results/*.trx
reporter: dotnet-trx
fail-on-error: false
fail-on-error: true

- name: Copy NuGet packages
shell: bash
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ SlimMessageBus is a client façade for message brokers for .NET. It comes with i
| `.Host.Interceptor` | Core interface for interceptors | [![NuGet](https://img.shields.io/nuget/v/SlimMessageBus.Host.Interceptor.svg)](https://www.nuget.org/packages/SlimMessageBus.Host.Interceptor) |
| `.Host.FluentValidation` | Validation for messages based on [FluentValidation](https://www.nuget.org/packages/FluentValidation) | [![NuGet](https://img.shields.io/nuget/v/SlimMessageBus.Host.FluentValidation.svg)](https://www.nuget.org/packages/SlimMessageBus.Host.FluentValidation) |
| `.Host.Outbox.Sql` | Transactional Outbox using SQL | [![NuGet](https://img.shields.io/nuget/v/SlimMessageBus.Host.Outbox.Sql.svg)](https://www.nuget.org/packages/SlimMessageBus.Host.Outbox.Sql) |
| `.Host.Outbox.DbContext` | Transactional Outbox using EF DbContext | [![NuGet](https://img.shields.io/nuget/v/SlimMessageBus.Host.Outbox.DbContext.svg)](https://www.nuget.org/packages/SlimMessageBus.Host.Outbox.DbContext) |
| `.Host.Outbox.Sql.DbContext` | Transactional Outbox using EF DbContext | [![NuGet](https://img.shields.io/nuget/v/SlimMessageBus.Host.Outbox.Sql.DbContext.svg)](https://www.nuget.org/packages/SlimMessageBus.Host.Outbox.Sql.DbContext) |
| `.Host.AsyncApi` | [AsyncAPI](https://www.asyncapi.com/) specification generation via [Saunter](https://github.com/tehmantra/saunter) | [![NuGet](https://img.shields.io/nuget/v/SlimMessageBus.Host.AsyncApi.svg)](https://www.nuget.org/packages/SlimMessageBus.Host.AsyncApi) |

Typically the application layers (domain model, business logic) only need to depend on `SlimMessageBus` which is the facade, and ultimately the application hosting layer (ASP.NET, Console App, Windows Service) will reference and configure the other packages (`SlimMessageBus.Host.*`) which are the messaging transport providers and additional plugins.
Expand Down
2 changes: 1 addition & 1 deletion build/tasks.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ $projects = @(

"SlimMessageBus.Host.Outbox",
"SlimMessageBus.Host.Outbox.Sql",
"SlimMessageBus.Host.Outbox.DbContext",
"SlimMessageBus.Host.Outbox.Sql.DbContext",

"SlimMessageBus.Host.AsyncApi"
)
Expand Down
11 changes: 6 additions & 5 deletions docs/plugin_outbox.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Please read the [Introduction](intro.md) before reading this provider documentat
- [UseTransactionScope](#usetransactionscope)
- [UseSqlTransaction](#usesqltransaction)
- [How it works](#how-it-works)
- [Important note](#important-note)

## Introduction

Expand All @@ -27,15 +28,15 @@ Outbox plugin can work in combination with any transport provider.

### Entity Framework

> Required: [`SlimMessageBus.Host.Outbox.DbContext`](https://www.nuget.org/packages/SlimMessageBus.Host.Outbox.DbContext)
> Required: [`SlimMessageBus.Host.Outbox.Sql.DbContext`](https://www.nuget.org/packages/SlimMessageBus.Host.Outbox.Sql.DbContext)
```cs
using SlimMessageBus.Host.Outbox.DbContext;
using SlimMessageBus.Host.Outbox.Sql.DbContext;
```

Consider the following example (from [Samples](../src/Samples/Sample.OutboxWebApi/Program.cs)):

- `services.AddOutboxUsingDbContext<CustomerContext>(...)` is used to add the [Outbox.DbContext](https://www.nuget.org/packages/SlimMessageBus.Host.Outbox.DbContext) plugin to the container.
- `services.AddOutboxUsingDbContext<CustomerContext>(...)` is used to add the [Outbox.DbContext](https://www.nuget.org/packages/SlimMessageBus.Host.Outbox.Sql.DbContext) plugin to the container.
- `CustomerContext` is the application specific Entity Framework `DbContext`.
- `CustomerCreatedEvent` is produced on the `AzureSB` child bus, the bus will deliver these events via outbox - see `.UseOutbox()`
- `CreateCustomerCommand` is consumed on the `Memory` child bus, each command is wrapped in an SQL transaction - see `UseSqlTransaction()`
Expand Down Expand Up @@ -181,7 +182,7 @@ When applied on the (child) bus level then all consumers (or handlers) will inhe

#### UseSqlTransaction

> Required: [`SlimMessageBus.Host.Outbox.Sql`](https://www.nuget.org/packages/SlimMessageBus.Host.Outbox.Sql) or [`SlimMessageBus.Host.Outbox.DbContext`](https://www.nuget.org/packages/SlimMessageBus.Host.Outbox.DbContext)
> Required: [`SlimMessageBus.Host.Outbox.Sql`](https://www.nuget.org/packages/SlimMessageBus.Host.Outbox.Sql) or [`SlimMessageBus.Host.Outbox.Sql.DbContext`](https://www.nuget.org/packages/SlimMessageBus.Host.Outbox.Sql.DbContext)
```cs
using SlimMessageBus.Host.Outbox.Sql;
Expand Down Expand Up @@ -218,6 +219,6 @@ When applied on the (child) bus level then all consumers (or handlers) will inhe

## Important note

As the outbox can be processed by instance of the application that did not originally process it, it is important to ensure that all active instances maintian the same message registrations (and compatible JSON schema definitions).
As the outbox can be processed by instance of the application that did not originally process it, it is important to ensure that all active instances maintain the same message registrations (and compatible JSON schema definitions).

A message that fails to deserialize will be flagged as invalid by setting the associated `DeliveryAborted` field in the `Outbox` table, to `1`. It is safe to manually reset this field value to `0` once the version incompatibility has been resolved.
13 changes: 7 additions & 6 deletions docs/plugin_outbox.t.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Please read the [Introduction](intro.md) before reading this provider documentat
- [UseTransactionScope](#usetransactionscope)
- [UseSqlTransaction](#usesqltransaction)
- [How it works](#how-it-works)
- [Important note](#important-note)

## Introduction

Expand All @@ -27,15 +28,15 @@ Outbox plugin can work in combination with any transport provider.

### Entity Framework

> Required: [`SlimMessageBus.Host.Outbox.DbContext`](https://www.nuget.org/packages/SlimMessageBus.Host.Outbox.DbContext)
> Required: [`SlimMessageBus.Host.Outbox.Sql.DbContext`](https://www.nuget.org/packages/SlimMessageBus.Host.Outbox.Sql.DbContext)
```cs
using SlimMessageBus.Host.Outbox.DbContext;
using SlimMessageBus.Host.Outbox.Sql.DbContext;
```

Consider the following example (from [Samples](../src/Samples/Sample.OutboxWebApi/Program.cs)):

- `services.AddOutboxUsingDbContext<CustomerContext>(...)` is used to add the [Outbox.DbContext](https://www.nuget.org/packages/SlimMessageBus.Host.Outbox.DbContext) plugin to the container.
- `services.AddOutboxUsingDbContext<CustomerContext>(...)` is used to add the [Outbox.DbContext](https://www.nuget.org/packages/SlimMessageBus.Host.Outbox.Sql.DbContext) plugin to the container.
- `CustomerContext` is the application specific Entity Framework `DbContext`.
- `CustomerCreatedEvent` is produced on the `AzureSB` child bus, the bus will deliver these events via outbox - see `.UseOutbox()`
- `CreateCustomerCommand` is consumed on the `Memory` child bus, each command is wrapped in an SQL transaction - see `UseSqlTransaction()`
Expand Down Expand Up @@ -112,7 +113,7 @@ When applied on the (child) bus level then all consumers (or handlers) will inhe

#### UseSqlTransaction

> Required: [`SlimMessageBus.Host.Outbox.Sql`](https://www.nuget.org/packages/SlimMessageBus.Host.Outbox.Sql) or [`SlimMessageBus.Host.Outbox.DbContext`](https://www.nuget.org/packages/SlimMessageBus.Host.Outbox.DbContext)
> Required: [`SlimMessageBus.Host.Outbox.Sql`](https://www.nuget.org/packages/SlimMessageBus.Host.Outbox.Sql) or [`SlimMessageBus.Host.Outbox.Sql.DbContext`](https://www.nuget.org/packages/SlimMessageBus.Host.Outbox.Sql.DbContext)
```cs
using SlimMessageBus.Host.Outbox.Sql;
Expand Down Expand Up @@ -149,6 +150,6 @@ When applied on the (child) bus level then all consumers (or handlers) will inhe

## Important note

As the outbox can be processed by instance of the application that did not originally process it, it is important to ensure that all active instances maintian the same message registrations (and compatible JSON schema definitions).
As the outbox can be processed by instance of the application that did not originally process it, it is important to ensure that all active instances maintain the same message registrations (and compatible JSON schema definitions).

A message that fails to deserialize will be flagged as invalid by setting the associated `DeliveryAborted` field in the `Outbox` table, to `1`. It is safe to manually reset this field value to `0` once the version incompatibility has been resolved.
A message that fails to deserialize will be flagged as invalid by setting the associated `DeliveryAborted` field in the `Outbox` table, to `1`. It is safe to manually reset this field value to `0` once the version incompatibility has been resolved.
9 changes: 5 additions & 4 deletions docs/provider_kafka.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ When troubleshooting or fine tuning it is worth reading the `librdkafka` and `co

## Configuration properties

Producer, consumer and global configuration properties are described [here](https://github.com/edenhill/librdkafka/blob/master/CONFIGURATION.md).
Producer, consumer and global configuration properties are described [here](https://github.com/confluentinc/librdkafka/blob/master/CONFIGURATION.md).
The configuration on the underlying Kafka client can be adjusted like so:

```cs
Expand All @@ -53,7 +53,7 @@ services.AddSlimMessageBus(mbb =>

### Minimizing message latency

There is a good description [here](https://github.com/edenhill/librdkafka/wiki/How-to-decrease-message-latency) on improving the latency by applying producer/consumer settings on librdkafka. Here is how you enter the settings using SlimMessageBus:
There is a good description [here](https://github.com/confluentinc/librdkafka/wiki/How-to-decrease-message-latency) on improving the latency by applying producer/consumer settings on librdkafka. Here is how you enter the settings using SlimMessageBus:

```cs
services.AddSlimMessageBus(mbb =>
Expand Down Expand Up @@ -176,7 +176,7 @@ public class PingConsumer : IConsumer<PingMessage>, IConsumerWithContext
{
public IConsumerContext Context { get; set; }

public Task OnHandle(PingMessage message, CancellationToken cancellationToken)
public Task OnHandle(PingMessage message)
{
// SMB Kafka transport specific extension:
var transportMessage = Context.GetTransportMessage();
Expand Down Expand Up @@ -211,7 +211,8 @@ mbb

### Offset Commit

In the current Kafka provider implementation, SMB handles the manual commit of topic-partition offsets for the consumer. This configuration is controlled through the following methods on the consumer builder:
In the current Kafka provider implementation, SMB handles the manual commit of topic-partition offsets for the consumer.Th
is configuration is controlled through the following methods on the consumer builder:

- `CheckpointEvery(int)` – Commits the offset after a specified number of processed messages.
- `CheckpointAfter(TimeSpan)` – Commits the offset after a specified time interval.
Expand Down
2 changes: 1 addition & 1 deletion src/Host.Plugin.Properties.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Import Project="Common.NuGet.Properties.xml" />

<PropertyGroup>
<Version>3.0.0-rc11</Version>
<Version>3.0.0-rc12</Version>
</PropertyGroup>

</Project>
2 changes: 1 addition & 1 deletion src/Samples/Sample.OutboxWebApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
using SlimMessageBus.Host.AzureServiceBus;
using SlimMessageBus.Host.Memory;
using SlimMessageBus.Host.Outbox;
using SlimMessageBus.Host.Outbox.DbContext;
using SlimMessageBus.Host.Outbox.Sql;
using SlimMessageBus.Host.Outbox.Sql.DbContext;
using SlimMessageBus.Host.Serialization.Json;

// Local file with secrets
Expand Down
4 changes: 1 addition & 3 deletions src/Samples/Sample.OutboxWebApi/Sample.OutboxWebApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
<ProjectReference Include="..\..\SlimMessageBus.Host.AspNetCore\SlimMessageBus.Host.AspNetCore.csproj" />
<ProjectReference Include="..\..\SlimMessageBus.Host.AzureServiceBus\SlimMessageBus.Host.AzureServiceBus.csproj" />
<ProjectReference Include="..\..\SlimMessageBus.Host.Memory\SlimMessageBus.Host.Memory.csproj" />
<ProjectReference Include="..\..\SlimMessageBus.Host.Outbox.DbContext\SlimMessageBus.Host.Outbox.DbContext.csproj" />
<ProjectReference Include="..\..\SlimMessageBus.Host.Outbox.Sql\SlimMessageBus.Host.Outbox.Sql.csproj" />
<ProjectReference Include="..\..\SlimMessageBus.Host.Outbox\SlimMessageBus.Host.Outbox.csproj" />
<ProjectReference Include="..\..\SlimMessageBus.Host.Outbox.Sql.DbContext\SlimMessageBus.Host.Outbox.Sql.DbContext.csproj" />
<ProjectReference Include="..\..\SlimMessageBus.Host.Serialization.Json\SlimMessageBus.Host.Serialization.Json.csproj" />
<ProjectReference Include="..\..\Tools\SecretStore\SecretStore.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<Description>Core configuration interfaces of SlimMessageBus</Description>
<PackageTags>SlimMessageBus</PackageTags>
<RootNamespace>SlimMessageBus.Host</RootNamespace>
<Version>3.0.0-rc11</Version>
<Version>3.0.0-rc12</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Import Project="../Common.NuGet.Properties.xml" />

<PropertyGroup>
<Version>3.0.0-rc11</Version>
<Version>3.0.0-rc12</Version>
<Description>Core interceptor interfaces of SlimMessageBus</Description>
<PackageTags>SlimMessageBus</PackageTags>
</PropertyGroup>
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace SlimMessageBus.Host.Outbox.Sql.DbContext;

public static class MessageBusBuilderExtensions
{
public static MessageBusBuilder AddOutboxUsingDbContext<TDbContext>(this MessageBusBuilder mbb, Action<SqlOutboxSettings> configure)
where TDbContext : Microsoft.EntityFrameworkCore.DbContext
{
mbb.PostConfigurationActions.Add(services =>
{
services.TryAddScoped<ISqlTransactionService, DbContextTransactionService<TDbContext>>();
services.TryAddScoped(svp =>
{
var settings = svp.GetRequiredService<SqlOutboxSettings>();
return new DbContextOutboxRepository<TDbContext>(
svp.GetRequiredService<ILogger<DbContextOutboxRepository<TDbContext>>>(),
settings,
svp.GetRequiredService<SqlOutboxTemplate>(),
settings.IdGeneration.GuidGenerator ?? (IGuidGenerator)svp.GetRequiredService(settings.IdGeneration.GuidGeneratorType),
svp.GetRequiredService<ICurrentTimeProvider>(),
svp.GetRequiredService<IInstanceIdProvider>(),
svp.GetRequiredService<TDbContext>(),
svp.GetRequiredService<ISqlTransactionService>()
);
});
});
return mbb.AddOutboxUsingSql<DbContextOutboxRepository<TDbContext>>(configure);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace SlimMessageBus.Host.Outbox.Sql.DbContext;

public class DbContextOutboxRepository<TDbContext> : SqlOutboxMessageRepository where TDbContext : Microsoft.EntityFrameworkCore.DbContext
{
public TDbContext DbContext { get; }

public DbContextOutboxRepository(
ILogger<DbContextOutboxRepository<TDbContext>> logger,
SqlOutboxSettings settings,
SqlOutboxTemplate sqlOutboxTemplate,
IGuidGenerator guidGenerator,
ICurrentTimeProvider currentTimeProvider,
IInstanceIdProvider instanceIdProvider,
TDbContext dbContext,
ISqlTransactionService transactionService)
: base(
logger,
settings,
sqlOutboxTemplate,
guidGenerator,
currentTimeProvider,
instanceIdProvider,
(SqlConnection)dbContext.Database.GetDbConnection(),
transactionService)
{
DbContext = dbContext;
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
namespace SlimMessageBus.Host.Outbox.DbContext;

using Microsoft.Data.SqlClient;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Storage;

using SlimMessageBus.Host.Sql.Common;
namespace SlimMessageBus.Host.Outbox.Sql.DbContext;

public class DbContextTransactionService<TDbContext>(TDbContext dbContext, ISqlSettings sqlSettings)
: AbstractSqlTransactionService((SqlConnection)dbContext.Database.GetDbConnection())
where TDbContext : DbContext
where TDbContext : Microsoft.EntityFrameworkCore.DbContext
{
public TDbContext DbContext { get; } = dbContext;

Expand Down
8 changes: 8 additions & 0 deletions src/SlimMessageBus.Host.Outbox.Sql.DbContext/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
global using Microsoft.Data.SqlClient;
global using Microsoft.EntityFrameworkCore;
global using Microsoft.EntityFrameworkCore.Storage;
global using Microsoft.Extensions.DependencyInjection;
global using Microsoft.Extensions.DependencyInjection.Extensions;
global using Microsoft.Extensions.Logging;

global using SlimMessageBus.Host.Sql.Common;
Loading

0 comments on commit eb6bd33

Please sign in to comment.