Skip to content

Commit 01ce9cc

Browse files
Add Akka.Hosting v1.5.51 health check documentation to README (#548)
- Added new section explaining persistence health checks - Included code examples for both basic and ASP.NET Core configurations - Updated table of contents - Documents WithHealthCheck() method for journal and snapshot stores
1 parent 097be1d commit 01ce9cc

File tree

1 file changed

+63
-3
lines changed

1 file changed

+63
-3
lines changed

README.md

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ If you're migrating from legacy `Akka.Persistence.Sql.Common` based plugins, you
1212
- [Akka.Persistence.Sql](#akkapersistencesql)
1313
- [Getting Started](#getting-started)
1414
* [The Easy Way, Using `Akka.Hosting`](#the-easy-way-using-akkahosting)
15+
+ [Health Checks (Akka.Hosting v1.5.51+)](#health-checks-akkahosting-v1551)
1516
* [The Classic Way, Using HOCON](#the-classic-way-using-hocon)
1617
* [Supported Database Providers](#supported-database-providers)
1718
+ [Tested Database Providers](#tested-database-providers)
@@ -70,11 +71,70 @@ var host = new HostBuilder()
7071
});
7172
});
7273
```
73-
If `dataOptions` are provided, you must supply enough information for linq2db to connect to the database.
74-
This includes setting the connection string and provider name again, if necessary for your use case.
75-
Please consult the Linq2Db documentation for more details on configuring a valid DataOptions object.
74+
If `dataOptions` are provided, you must supply enough information for linq2db to connect to the database.
75+
This includes setting the connection string and provider name again, if necessary for your use case.
76+
Please consult the Linq2Db documentation for more details on configuring a valid DataOptions object.
7677
Note that `MappingSchema` and `RetryPolicy` will always be overridden by Akka.Persistence.Sql.
7778

79+
### Health Checks (Akka.Hosting v1.5.51+)
80+
81+
Starting with Akka.Hosting v1.5.51, you can add health checks for your persistence plugins to verify that journals and snapshot stores are properly initialized and accessible. These health checks integrate with `Microsoft.Extensions.Diagnostics.HealthChecks` and can be used with ASP.NET Core health check endpoints.
82+
83+
To configure health checks, use the `.WithHealthCheck()` method when setting up your journal and snapshot store:
84+
85+
```csharp
86+
var host = new HostBuilder()
87+
.ConfigureServices((context, services) => {
88+
services.AddAkka("my-system-name", (builder, provider) =>
89+
{
90+
builder
91+
.WithSqlPersistence(
92+
connectionString: _myConnectionString,
93+
providerName: ProviderName.SqlServer2019,
94+
journal: j => j.WithHealthCheck(
95+
unHealthyStatus: HealthStatus.Degraded,
96+
name: "sql-journal"),
97+
snapshot: s => s.WithHealthCheck(
98+
unHealthyStatus: HealthStatus.Degraded,
99+
name: "sql-snapshot"));
100+
});
101+
});
102+
```
103+
104+
The health checks will automatically:
105+
- Verify the persistence plugin is configured correctly
106+
- Test connectivity to the underlying storage (database, cloud storage, etc.)
107+
- Report `Healthy` when the plugin is operational
108+
- Report `Degraded` or `Unhealthy` (configurable) when issues are detected
109+
110+
Health checks are tagged with `akka`, `persistence`, and either `journal` or `snapshot-store` for filtering purposes.
111+
112+
For ASP.NET Core applications, you can expose these health checks via an endpoint:
113+
114+
```csharp
115+
var builder = WebApplication.CreateBuilder(args);
116+
117+
// Add health checks service
118+
builder.Services.AddHealthChecks();
119+
120+
builder.Services.AddAkka("my-system-name", (configBuilder, provider) =>
121+
{
122+
configBuilder
123+
.WithSqlPersistence(
124+
connectionString: _myConnectionString,
125+
providerName: ProviderName.SqlServer2019,
126+
journal: j => j.WithHealthCheck(),
127+
snapshot: s => s.WithHealthCheck());
128+
});
129+
130+
var app = builder.Build();
131+
132+
// Map health check endpoint
133+
app.MapHealthChecks("/healthz");
134+
135+
app.Run();
136+
```
137+
78138
## The Classic Way, Using HOCON
79139

80140
These are the minimum HOCON configuration you need to start using Akka.Persistence.Sql:

0 commit comments

Comments
 (0)