Skip to content

Commit

Permalink
Ensure the primary node is used in multi-host environments
Browse files Browse the repository at this point in the history
  • Loading branch information
Hawxy authored and jeremydmiller committed Nov 4, 2024
1 parent 37cdaa9 commit 2cca2f4
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,17 @@ internal class PostgresqlMessageStore : MessageDatabase<NpgsqlConnection>, IData


public PostgresqlMessageStore(DatabaseSettings databaseSettings, DurabilitySettings settings, NpgsqlDataSource dataSource,
ILogger<PostgresqlMessageStore> logger) : this(databaseSettings, settings, dataSource, logger, Array.Empty<SagaTableDefinition>())
ILogger<PostgresqlMessageStore> logger) : this(databaseSettings, settings, GetPrimaryNpgsqlNodeIfPossible(dataSource), logger, Array.Empty<SagaTableDefinition>())
{
}

private static NpgsqlDataSource GetPrimaryNpgsqlNodeIfPossible(NpgsqlDataSource dataSource)
{
if (dataSource is NpgsqlMultiHostDataSource multiHost)
return multiHost.WithTargetSession(TargetSessionAttributes.Primary);
return dataSource;
}

public PostgresqlMessageStore(DatabaseSettings databaseSettings, DurabilitySettings settings, NpgsqlDataSource dataSource,
ILogger<PostgresqlMessageStore> logger, IEnumerable<SagaTableDefinition> sagaTypes) : base(databaseSettings, dataSource,
settings, logger, new PostgresqlMigrator(), "public")
Expand Down

0 comments on commit 2cca2f4

Please sign in to comment.