Publo.Postgres
1.0.0
See the version list below for details.
dotnet add package Publo.Postgres --version 1.0.0
NuGet\Install-Package Publo.Postgres -Version 1.0.0
<PackageReference Include="Publo.Postgres" Version="1.0.0" />
<PackageVersion Include="Publo.Postgres" Version="1.0.0" />
<PackageReference Include="Publo.Postgres" />
paket add Publo.Postgres --version 1.0.0
#r "nuget: Publo.Postgres, 1.0.0"
#:package Publo.Postgres@1.0.0
#addin nuget:?package=Publo.Postgres&version=1.0.0
#tool nuget:?package=Publo.Postgres&version=1.0.0
Publo.Postgres
PostgreSQL provider for Publo. It stores sent messages in PostgreSQL, runs migrations for the Publo
schema, and starts a hosted runner that polls stored messages and dispatches them to
IPubloExecutor<T> handlers.
Installation
dotnet add package Publo.Postgres
Registration
Register Publo with the PostgreSQL provider and supply an IConnectionFactory implementation:
using System.Data.Common;
using Npgsql;
using Publo.Abstraction.Extensions;
using Publo.Postgres.Extensions;
using Publo.Postgres.Infrastructure.Database;
builder.Services
.AddPublo(publo => publo.UseNpgsql<ConnectionFactory>())
.AddPubloExecutor<UserCreated, UserCreatedExecutor>();
public sealed class ConnectionFactory(IConfiguration configuration) : IConnectionFactory
{
public string GetConnectionString()
=> configuration.GetConnectionString("Postgres")
?? throw new InvalidOperationException("Postgres connection string not found.");
public Task<DbConnection> GetConnectionAsync(CancellationToken cancellationToken)
=> Task.FromResult<DbConnection>(new NpgsqlConnection(GetConnectionString()));
}
UseNpgsql<T> registers the provider, repository, migrations, options binding, and polling hosted
service.
Configuration
UseNpgsql<T> binds options from the PostgresPubloOptions configuration section:
{
"ConnectionStrings": {
"Postgres": "Host=localhost;Port=5432;Database=postgres;Username=postgres;Password=pwd;"
},
"PostgresPubloOptions": {
"schemaName": "publo",
"pollingInterval": "00:00:05",
"offsetPolicy": "Latest"
}
}
Options:
| Name | Default | Description |
|---|---|---|
SchemaName |
publo |
PostgreSQL schema used for Publo tables and migration metadata. |
PollingInterval |
00:00:05 |
Delay between polling attempts after the current batch is drained. |
OffsetPolicy |
Latest |
Controls where a new runner starts reading messages. |
OffsetPolicy.Latest starts from messages created after the runner starts. OffsetPolicy.Earliest
starts from the earliest uncommitted message available to the runner.
Sending And Handling
using Publo.Abstraction.Executor;
using Publo.Abstraction.Services;
public sealed record UserCreated(Guid UserId);
public sealed class UserCreatedExecutor : IPubloExecutor<UserCreated>
{
public Task HandleAsync(UserCreated message, CancellationToken cancellationToken)
{
// Handle the message here.
return Task.CompletedTask;
}
}
public sealed class UsersService(IPubloService publo)
{
public Task PublishAsync(Guid userId, CancellationToken cancellationToken)
=> publo.SendAsync(new UserCreated(userId), cancellationToken);
}
Local PostgreSQL
The repository docker-compose.yaml starts PostgreSQL on localhost:5432:
docker compose up -d postgres
Default local credentials are postgres / pwd, database postgres.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- DistributedLock.Postgres (>= 1.3.0)
- FluentMigrator.Runner (>= 7.1.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.8)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.8)
- Npgsql (>= 10.0.2)
- Polly (>= 8.6.6)
- Publo.Abstraction (>= 1.0.0)
- StronglyTypedId (>= 0.2.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.