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
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ A basic lambda function can handle it - the only reason this function is as comp
<XunitVersion>2.8.1</XunitVersion>
<TestSdkVersion>17.11.1</TestSdkVersion>
<CoverletVersion>6.0.3</CoverletVersion>
<XunitRunneVisualstudio>3.1.5</XunitRunneVisualstudio>
<AkkaVersion>1.5.50</AkkaVersion>
<XunitRunneVisualstudio>3.1.5</XunitRunneVisualstudio>
<AkkaVersion>1.5.51</AkkaVersion>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upgraded to Akka.NET v1.5.51 in order to get access to akkadotnet/akka.net#7842

<MicrosoftExtensionsVersion>[6.0.0,)</MicrosoftExtensionsVersion>
<SystemTextJsonVersion>[6.0.10,)</SystemTextJsonVersion>
</PropertyGroup>
Expand Down
64 changes: 64 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -778,5 +778,69 @@ Akka.Hosting and its other packages ship with some built-in health checks:

* `WithActorSystemLivenessCheck()` - a liveness probe that will fail if the `ActorSystem` is terminated. Generally, Akka.Hosting will try to shut down your process anyway if the `ActorSystem` dies.
* `WithAkkaClusterReadinessCheck` - if you are an Akka.Cluster user, this health check will return `HealthStatus.Unhealthy` until you successfully join a cluster - that way you can stop load-balancers and other devices from routing traffic to this node until it has access to the cluster. This readiness check is also tagged with the `ready` tag for filtering purposes.
* **Akka.Persistence Health Checks** - verify that persistence plugins (journals and snapshot stores) are properly initialized and accessible. These health checks use the built-in Akka.Persistence health check APIs to validate plugin connectivity and functionality. Health checks are tagged with `akka`, `persistence`, and either `journal` or `snapshot-store` for filtering purposes.

#### Configuring Persistence Health Checks

You can add health checks for your persistence plugins using the `.WithHealthCheck()` method when configuring journals and snapshot stores:

```csharp
builder.Services.AddAkka("MyActorSystem", configurationBuilder =>
{
configurationBuilder
// Journal with health check
.WithJournal(
new SqlServerJournalOptions
{
ConnectionString = "...",
IsDefaultPlugin = true
},
journal => journal
.AddWriteEventAdapter<MyAdapter>("adapter", new[] { typeof(MyEvent) })
.WithHealthCheck(
unHealthyStatus: HealthStatus.Degraded,
name: "sql-journal"))

// Snapshot store with health check
.WithSnapshot(
new SqlServerSnapshotOptions
{
ConnectionString = "...",
IsDefaultPlugin = true
},
snapshot => snapshot
.WithHealthCheck(
unHealthyStatus: HealthStatus.Degraded,
name: "sql-snapshot"));
});
```

You can also configure both journal and snapshot health checks together:

```csharp
builder.Services.AddAkka("MyActorSystem", configurationBuilder =>
{
configurationBuilder
.WithJournalAndSnapshot(
new SqlServerJournalOptions
{
ConnectionString = "...",
IsDefaultPlugin = true
},
new SqlServerSnapshotOptions
{
ConnectionString = "...",
IsDefaultPlugin = true
},
journal => journal.WithHealthCheck(),
snapshot => snapshot.WithHealthCheck());
});
```

The health checks will automatically:
- Verify the persistence plugin is configured correctly
- Test connectivity to the underlying storage (database, cloud storage, etc.)
- Report `Healthy` when the plugin is operational
- Report `Degraded` or `Unhealthy` (configurable) when issues are detected

[Back to top](#akkahosting)
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@ namespace Akka.Persistence.Hosting
public static Akka.Hosting.AkkaConfigurationBuilder WithInMemoryJournal(this Akka.Hosting.AkkaConfigurationBuilder builder, System.Action<Akka.Persistence.Hosting.AkkaPersistenceJournalBuilder> journalBuilder, string journalId = "inmem", bool isDefaultPlugin = true) { }
public static Akka.Hosting.AkkaConfigurationBuilder WithInMemorySnapshotStore(this Akka.Hosting.AkkaConfigurationBuilder builder, string snapshotStoreId = "inmem", bool isDefaultPlugin = true) { }
public static Akka.Hosting.AkkaConfigurationBuilder WithJournal(this Akka.Hosting.AkkaConfigurationBuilder builder, Akka.Persistence.Hosting.JournalOptions journalOptions) { }
public static Akka.Hosting.AkkaConfigurationBuilder WithJournal(this Akka.Hosting.AkkaConfigurationBuilder builder, Akka.Persistence.Hosting.JournalOptions journalOptions, System.Action<Akka.Persistence.Hosting.AkkaPersistenceJournalBuilder>? configureBuilder) { }
[System.Obsolete("Use WithJournal(journalOptions, configureBuilder) instead to combine options conf" +
"iguration with event adapters and health checks. This method will be removed in " +
"v1.6.")]
public static Akka.Hosting.AkkaConfigurationBuilder WithJournal(this Akka.Hosting.AkkaConfigurationBuilder builder, string journalId, System.Action<Akka.Persistence.Hosting.AkkaPersistenceJournalBuilder> journalBuilder) { }
public static Akka.Hosting.AkkaConfigurationBuilder WithJournalAndSnapshot(this Akka.Hosting.AkkaConfigurationBuilder builder, Akka.Persistence.Hosting.JournalOptions journalOptions, Akka.Persistence.Hosting.SnapshotOptions snapshotOptions) { }
public static Akka.Hosting.AkkaConfigurationBuilder WithJournalAndSnapshot(this Akka.Hosting.AkkaConfigurationBuilder builder, Akka.Persistence.Hosting.JournalOptions journalOptions, Akka.Persistence.Hosting.SnapshotOptions snapshotOptions, System.Action<Akka.Persistence.Hosting.AkkaPersistenceJournalBuilder>? configureJournal, System.Action<Akka.Persistence.Hosting.AkkaPersistenceSnapshotBuilder>? configureSnapshot) { }
public static Akka.Hosting.AkkaConfigurationBuilder WithSnapshot(this Akka.Hosting.AkkaConfigurationBuilder builder, Akka.Persistence.Hosting.SnapshotOptions snapshotOptions) { }
public static Akka.Hosting.AkkaConfigurationBuilder WithSnapshot(this Akka.Hosting.AkkaConfigurationBuilder builder, Akka.Persistence.Hosting.SnapshotOptions snapshotOptions, System.Action<Akka.Persistence.Hosting.AkkaPersistenceSnapshotBuilder>? configureBuilder) { }
}
public sealed class AkkaPersistenceJournalBuilder
{
Expand All @@ -22,6 +28,12 @@ namespace Akka.Persistence.Hosting
where TAdapter : Akka.Persistence.Journal.IReadEventAdapter { }
public Akka.Persistence.Hosting.AkkaPersistenceJournalBuilder AddWriteEventAdapter<TAdapter>(string eventAdapterName, System.Collections.Generic.IEnumerable<System.Type> boundTypes)
where TAdapter : Akka.Persistence.Journal.IWriteEventAdapter { }
public Akka.Persistence.Hosting.AkkaPersistenceJournalBuilder WithHealthCheck(Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus unHealthyStatus = 1, string? name = null) { }
}
public sealed class AkkaPersistenceSnapshotBuilder
{
public AkkaPersistenceSnapshotBuilder(string snapshotStoreId, Akka.Hosting.AkkaConfigurationBuilder builder) { }
public Akka.Persistence.Hosting.AkkaPersistenceSnapshotBuilder WithHealthCheck(Microsoft.Extensions.Diagnostics.HealthChecks.HealthStatus unHealthyStatus = 1, string? name = null) { }
}
public static class Extensions
{
Expand Down
26 changes: 23 additions & 3 deletions src/Akka.Persistence.Hosting.Tests/EventAdapterSpecs.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Threading.Tasks;
using Akka.Actor;
using Akka.Configuration;
using Akka.Hosting;
using Akka.Persistence.Journal;
using Akka.Util;
Expand All @@ -17,11 +18,28 @@ public static async Task<IHost> StartHost(Action<IServiceCollection> testSetup)
{
var host = new HostBuilder()
.ConfigureServices(testSetup).Build();

await host.StartAsync();
return host;
}


// Mock SQL Server journal options for testing event adapters
private sealed class MockSqlServerJournalOptions : JournalOptions
{
public MockSqlServerJournalOptions() : base(isDefault: false)
{
Identifier = "sql-server";
}

public override string Identifier { get; set; }

protected override Config InternalDefaultConfig =>
ConfigurationFactory.ParseString(@"
class = ""Akka.Persistence.Journal.MemoryJournal, Akka.Persistence""
plugin-dispatcher = ""akka.actor.default-dispatcher""
");
}

public sealed class Event1{ }
public sealed class Event2{ }

Expand Down Expand Up @@ -81,7 +99,9 @@ public IEventSequence FromJournal(object evt, string manifest)

protected override void ConfigureAkka(AkkaConfigurationBuilder builder, IServiceProvider provider)
{
builder.WithJournal("sql-server", journalBuilder =>
// Using the new unified API: WithJournal(options, builder)
var journalOptions = new MockSqlServerJournalOptions();
builder.WithJournal(journalOptions, journalBuilder =>
{
journalBuilder.AddWriteEventAdapter<EventMapper1>("mapper1", new Type[] { typeof(Event1) });
journalBuilder.AddReadEventAdapter<ReadAdapter>("reader1", new Type[] { typeof(Event1) });
Expand Down
Loading