Skip to content

Commit

Permalink
add default Akka.Persistence config to journal
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaronontheweb committed Apr 30, 2024
1 parent 1f9833d commit 3d03db8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 24 deletions.
42 changes: 21 additions & 21 deletions src/Akka.Persistence.Hosting/AkkaPersistenceHostingExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public enum PersistenceMode
/// </summary>
SnapshotStore,
}

/// <summary>
/// Used to help build journal configurations
/// </summary>
Expand Down Expand Up @@ -59,15 +59,15 @@ public AkkaPersistenceJournalBuilder AddReadEventAdapter<TAdapter>(string eventA

return this;
}

public AkkaPersistenceJournalBuilder AddWriteEventAdapter<TAdapter>(string eventAdapterName,
IEnumerable<Type> boundTypes) where TAdapter : IWriteEventAdapter
{
AddAdapter<TAdapter>(eventAdapterName, boundTypes);

return this;
}

private void AddAdapter<TAdapter>(string eventAdapterName, IEnumerable<Type> boundTypes)
{
Adapters[eventAdapterName] = typeof(TAdapter);
Expand Down Expand Up @@ -95,7 +95,8 @@ internal void Build()

adapters.AppendLine("}");

var finalHocon = ConfigurationFactory.ParseString(adapters.ToString());
var finalHocon = ConfigurationFactory.ParseString(adapters.ToString())
.WithFallback(Persistence.DefaultConfig()); // add the default config as a fallback
Builder.AddHocon(finalHocon, HoconAddMode.Prepend);
}

Expand All @@ -104,7 +105,7 @@ internal void AppendAdapters(StringBuilder sb)
// useless configuration - don't bother.
if (Adapters.Count == 0 || Bindings.Count == 0)
return;

sb.AppendLine("event-adapters {");
foreach (var kv in Adapters)
{
Expand Down Expand Up @@ -136,25 +137,25 @@ public static class AkkaPersistenceHostingExtensions
/// <exception cref="ArgumentNullException"></exception>
public static AkkaConfigurationBuilder WithJournalAndSnapshot(
this AkkaConfigurationBuilder builder,
JournalOptions journalOptions,
JournalOptions journalOptions,
SnapshotOptions snapshotOptions)
{
if (journalOptions is null)
throw new ArgumentNullException(nameof(journalOptions));
if (snapshotOptions is null)
throw new ArgumentNullException(nameof(snapshotOptions));

builder.AddHocon(journalOptions.ToConfig(), HoconAddMode.Prepend);
var defaultConfig = journalOptions.DefaultConfig;

builder.AddHocon(snapshotOptions.ToConfig(), HoconAddMode.Prepend);
defaultConfig = defaultConfig.Equals(snapshotOptions.DefaultConfig)
? defaultConfig
: defaultConfig.WithFallback(snapshotOptions.DefaultConfig);
? defaultConfig
: defaultConfig.WithFallback(snapshotOptions.DefaultConfig);

return builder.AddHocon(defaultConfig, HoconAddMode.Append);
}

/// <summary>
/// A generic way to add journal configuration to the <see cref="ActorSystem"/>
/// </summary>
Expand All @@ -168,11 +169,11 @@ public static AkkaConfigurationBuilder WithJournal(
{
if (journalOptions is null)
throw new ArgumentNullException(nameof(journalOptions));

builder.AddHocon(journalOptions.ToConfig(), HoconAddMode.Prepend);
return builder.AddHocon(journalOptions.DefaultConfig, HoconAddMode.Append);
}

/// <summary>
/// A generic way to add snapshot store configuration to the <see cref="ActorSystem"/>
/// </summary>
Expand All @@ -186,11 +187,11 @@ public static AkkaConfigurationBuilder WithSnapshot(
{
if (snapshotOptions is null)
throw new ArgumentNullException(nameof(snapshotOptions));

builder.AddHocon(snapshotOptions.ToConfig(), HoconAddMode.Prepend);
return builder.AddHocon(snapshotOptions.DefaultConfig, HoconAddMode.Append);
}

/// <summary>
/// Used to configure a specific Akka.Persistence.Journal instance, primarily to support <see cref="IEventAdapter"/>s.
/// </summary>
Expand All @@ -203,7 +204,7 @@ public static AkkaConfigurationBuilder WithSnapshot(
/// </remarks>
public static AkkaConfigurationBuilder WithJournal(
this AkkaConfigurationBuilder builder,
string journalId,
string journalId,
Action<AkkaPersistenceJournalBuilder> journalBuilder)
{
var jBuilder = new AkkaPersistenceJournalBuilder(journalId, builder);
Expand All @@ -213,7 +214,7 @@ public static AkkaConfigurationBuilder WithJournal(
jBuilder.Build();
return builder;
}

public static AkkaConfigurationBuilder WithInMemoryJournal(this AkkaConfigurationBuilder builder)
{
return WithInMemoryJournal(builder, _ => { });
Expand All @@ -227,8 +228,8 @@ public static AkkaConfigurationBuilder WithInMemoryJournal(
{
builder.WithJournal(journalId, journalBuilder);

var liveConfig =
@$"{(isDefaultPlugin ? $"akka.persistence.journal.plugin = akka.persistence.journal.{journalId}" : "")}
var liveConfig =
@$"{(isDefaultPlugin ? $"akka.persistence.journal.plugin = akka.persistence.journal.{journalId}" : "")}
akka.persistence.journal.{journalId} {{
class = ""Akka.Persistence.Journal.MemoryJournal, Akka.Persistence""
plugin-dispatcher = ""akka.actor.default-dispatcher""
Expand All @@ -242,8 +243,8 @@ public static AkkaConfigurationBuilder WithInMemorySnapshotStore(
string snapshotStoreId = "inmem",
bool isDefaultPlugin = true)
{
var liveConfig =
$@"{(isDefaultPlugin ? $"akka.persistence.snapshot-store.plugin = akka.persistence.snapshot-store.{snapshotStoreId}" : "")}
var liveConfig =
$@"{(isDefaultPlugin ? $"akka.persistence.snapshot-store.plugin = akka.persistence.snapshot-store.{snapshotStoreId}" : "")}
akka.persistence.snapshot-store.{snapshotStoreId} {{
class = ""Akka.Persistence.Snapshot.MemorySnapshotStore, Akka.Persistence""
plugin-dispatcher = ""akka.actor.default-dispatcher""
Expand Down Expand Up @@ -284,6 +285,5 @@ public static AkkaConfigurationBuilder WithClusterShardingJournalMigrationAdapte
}}";
return builder.AddHocon(config, HoconAddMode.Prepend);
}

}
}
5 changes: 2 additions & 3 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
<PropertyGroup>
<Copyright>Copyright © 2013-2023 Akka.NET Team</Copyright>
<Authors>Akka.NET Team</Authors>
<VersionPrefix>1.5.15</VersionPrefix>
<PackageReleaseNotes>• [Update Akka.NET to 1.5.15](https://github.com/akkadotnet/akka.net/releases/tag/1.5.15)
• Marked all Akka.Cluster.Hosting methods that accept deprecated sharding delegates as Obsolete</PackageReleaseNotes>
<VersionPrefix>1.5.19</VersionPrefix>
<PackageReleaseNotes>• [Update Akka.NET to 1.5.19](https://github.com/akkadotnet/akka.net/releases/tag/1.5.19)</PackageReleaseNotes>
<PackageIcon>akkalogo.png</PackageIcon>
<PackageProjectUrl>
https://github.com/akkadotnet/Akka.Hosting
Expand Down

0 comments on commit 3d03db8

Please sign in to comment.