Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/guide/durability/marten/ancillary-stores.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ theHost = await Host.CreateDefaultBuilder()
{

// THIS IS IMPORTANT FOR MODULAR MONOLITH USAGE!
// This helps Wolverine utilize the same envelope storage within the same database,
// and helps the system not waste resources
opts.Durability.MessageStorageSchemaName = "wolverine";

opts.Services.AddMarten(Servers.PostgresConnectionString).IntegrateWithWolverine();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public async Task InitializeAsync()
#region sample_using_message_storage_schema_name

// THIS IS IMPORTANT FOR MODULAR MONOLITH USAGE!
// This helps Wolverine out to always utilize the same envelope storage
// for all modules for more efficient usage of resources
opts.Durability.MessageStorageSchemaName = "wolverine";

#endregion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,11 @@ public static async Task options_important_for_modular_monolith()

builder.UseWolverine(opts =>
{
// This helps Wolverine to use a unified envelope storage across all
// modules, which in turn should help Wolverine be more efficient with
// your database
opts.Durability.MessageStorageSchemaName = "wolverine";

// Tell Wolverine that when you have more than one handler for the same
// message type, they should be executed separately and automatically
// "stuck" to separate local queues
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
using IntegrationTests;
using JasperFx.Resources;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Npgsql;
using Shouldly;
using Wolverine;
using Wolverine.Persistence.Durability;
using Wolverine.Postgresql;

namespace PostgresqlTests;

public class using_default_message_schema_name
{
[Fact]
public async Task use_default_schema_name_when_specified_for_connection_string()
{
using var host = await Host.CreateDefaultBuilder()
.UseWolverine(opts =>
{
opts.Durability.MessageStorageSchemaName = "wolverine_default";
opts.PersistMessagesWithPostgresql(Servers.PostgresConnectionString);

opts.Services.AddResourceSetupOnStartup();
}).StartAsync();

var store = host.Services.GetRequiredService<IMessageStore>();
store.ShouldBeOfType<PostgresqlMessageStore>().Settings.SchemaName.ShouldBe("wolverine_default");
}

[Fact]
public async Task override_the_storage_schema()
{
using var host = await Host.CreateDefaultBuilder()
.UseWolverine(opts =>
{
opts.Durability.MessageStorageSchemaName = "wolverine_default";
opts.PersistMessagesWithPostgresql(Servers.PostgresConnectionString, "non_default");

opts.Services.AddResourceSetupOnStartup();
}).StartAsync();

var store = host.Services.GetRequiredService<IMessageStore>();
store.ShouldBeOfType<PostgresqlMessageStore>().Settings.SchemaName.ShouldBe("non_default");
}

[Fact]
public async Task use_default_schema_name_when_specified_for_data_source()
{
using var host = await Host.CreateDefaultBuilder()
.UseWolverine(opts =>
{
opts.Durability.MessageStorageSchemaName = "wolverine_default";
opts.PersistMessagesWithPostgresql(NpgsqlDataSource.Create(Servers.PostgresConnectionString));

opts.Services.AddResourceSetupOnStartup();
}).StartAsync();

var store = host.Services.GetRequiredService<IMessageStore>();
store.ShouldBeOfType<PostgresqlMessageStore>().Settings.SchemaName.ShouldBe("wolverine_default");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using IntegrationTests;
using JasperFx.Resources;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Shouldly;
using Wolverine;
using Wolverine.Persistence.Durability;
using Wolverine.SqlServer;
using Wolverine.SqlServer.Persistence;

namespace SqlServerTests;

public class using_default_message_schema_name
{
[Fact]
public async Task use_default_schema_name_when_specified_for_connection_string()
{
using var host = await Host.CreateDefaultBuilder()
.UseWolverine(opts =>
{
opts.Durability.MessageStorageSchemaName = "wolverine_default";
opts.PersistMessagesWithSqlServer(Servers.SqlServerConnectionString);

opts.Services.AddResourceSetupOnStartup();
}).StartAsync();

var store = host.Services.GetRequiredService<IMessageStore>();
store.ShouldBeOfType<SqlServerMessageStore>().Settings.SchemaName.ShouldBe("wolverine_default");
}

[Fact]
public async Task override_the_storage_schema()
{
using var host = await Host.CreateDefaultBuilder()
.UseWolverine(opts =>
{
opts.Durability.MessageStorageSchemaName = "wolverine_default";
opts.PersistMessagesWithSqlServer(Servers.SqlServerConnectionString, "non_default");

opts.Services.AddResourceSetupOnStartup();
}).StartAsync();

var store = host.Services.GetRequiredService<IMessageStore>();
store.ShouldBeOfType<SqlServerMessageStore>().Settings.SchemaName.ShouldBe("non_default");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,16 @@ public interface IPostgresqlBackedPersistence
/// </summary>
internal class PostgresqlBackedPersistence : IPostgresqlBackedPersistence, IWolverineExtension
{
public PostgresqlBackedPersistence(DurabilitySettings settings)
{
EnvelopeStorageSchemaName = settings.MessageStorageSchemaName ?? "wolverine";
}

// Gotta have one or the other. Maybe even just DbDataSource here
public NpgsqlDataSource? DataSource { get; set; }
public string? ConnectionString { get; set; }

public string EnvelopeStorageSchemaName { get; set; } = "wolverine";
public string EnvelopeStorageSchemaName { get; set; }

// This needs to be an override, and we use JasperFxOptions first!
public AutoCreate AutoCreate { get; set; } = JasperFx.AutoCreate.CreateOrUpdate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ internal static void AssertValidSchemaName(this string schemaName)
public static IPostgresqlBackedPersistence PersistMessagesWithPostgresql(this WolverineOptions options, string connectionString,
string? schemaName = null)
{
var persistence = new PostgresqlBackedPersistence
var persistence = new PostgresqlBackedPersistence(options.Durability)
{
ConnectionString = connectionString,
};
Expand All @@ -62,7 +62,7 @@ public static IPostgresqlBackedPersistence PersistMessagesWithPostgresql(this Wo
public static IPostgresqlBackedPersistence PersistMessagesWithPostgresql(this WolverineOptions options, NpgsqlDataSource dataSource,
string? schemaName = null)
{
var persistence = new PostgresqlBackedPersistence
var persistence = new PostgresqlBackedPersistence(options.Durability)
{
DataSource = dataSource
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Weasel.Postgresql" Version="8.0.0-beta-10" />
<PackageReference Include="Weasel.Postgresql" Version="8.0.0-rc-3" />
</ItemGroup>

<Import Project="../../../Analysis.Build.props" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using JasperFx.Descriptors;
using Weasel.Core.Migrations;
using Wolverine.Persistence.Durability;
using Wolverine.Runtime;
Expand Down Expand Up @@ -48,4 +49,19 @@ public async ValueTask<IReadOnlyList<IDatabase>> BuildDatabases()
return master ?? group.First();
}).OfType<IDatabase>().ToList();
}

public DatabaseCardinality Cardinality
{
get
{
if (_runtime.Storage is MultiTenantedMessageStore tenantedMessageStore)
{
return tenantedMessageStore.Source.Cardinality;
}
else
{
return DatabaseCardinality.Single;
}
}
}
}
2 changes: 1 addition & 1 deletion src/Persistence/Wolverine.RDBMS/Wolverine.RDBMS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Weasel.Core" Version="8.0.0-rc-1" />
<PackageReference Include="Weasel.Core" Version="8.0.0-rc-3" />
</ItemGroup>

<Import Project="../../../Analysis.Build.props" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public Task ScheduleJobAsync(Envelope envelope)

public async Task MarkIncomingEnvelopeAsHandledAsync(Envelope envelope)
{
var expirationTime = DateTimeOffset.UtcNow.Add(_runtime.Options.Durability.KeepAfterMessageHandling);
var expirationTime = DateTimeOffset.UtcNow.Add(_options.Durability.KeepAfterMessageHandling);

var query = $@"
from IncomingMessages as m
Expand Down Expand Up @@ -139,7 +139,7 @@ where id() = $id

public async Task MarkIncomingEnvelopeAsHandledAsync(IReadOnlyList<Envelope> envelopes)
{
var expirationTime = DateTimeOffset.UtcNow.Add(_runtime.Options.Durability.KeepAfterMessageHandling);
var expirationTime = DateTimeOffset.UtcNow.Add(_options.Durability.KeepAfterMessageHandling);

var query = $@"
from IncomingMessages as m
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public async Task<bool> TryAttainLeadershipLockAsync(CancellationToken token)
{
var newLock = new DistributedLock
{
NodeId = _runtime!.Options.UniqueNodeId,
NodeId = _options.UniqueNodeId,
ExpirationTime = DateTimeOffset.UtcNow.AddMinutes(5),
};

Expand Down Expand Up @@ -69,7 +69,7 @@ public async Task<bool> TryAttainScheduledJobLockAsync(CancellationToken token)
{
var newLock = new DistributedLock
{
NodeId = _runtime!.Options.UniqueNodeId,
NodeId = _options.UniqueNodeId,
ExpirationTime = DateTimeOffset.UtcNow.AddMinutes(5),
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static class SqlServerConfigurationExtensions
/// </summary>
/// <param name="settings"></param>
/// <param name="connectionString"></param>
/// <param name="schema"></param>
/// <param name="schema">Potentially override the schema name for Wolverine envelope storage. Default is to use WolverineOptions.Durability.MessageStorageSchemaName ?? "dbo"</param>
public static ISqlServerBackedPersistence PersistMessagesWithSqlServer(this WolverineOptions options, string connectionString,
string? schema = null)
{
Expand All @@ -30,7 +30,7 @@ public static ISqlServerBackedPersistence PersistMessagesWithSqlServer(this Wolv
}
else
{
extension.EnvelopeStorageSchemaName = "dbo";
extension.EnvelopeStorageSchemaName = options.Durability.MessageStorageSchemaName ?? "dbo";
}

options.Include(extension);
Expand Down
Loading