Releases: akkadotnet/Akka.Hosting
0.5.1
0.5.0
• Update Akka.NET from 1.4.41 to 1.4.43
• Add full options support to Akka.Persistence.SqlServer.Hosting
• Improved Akka.Remote.Hosting implementation
• Add a standardized option code pattern for Akka.Hosting developer
• Add Akka.Hosting.TestKit module for unit testing projects using Akka.Hosting
Full options support for Akka.Persistence.SqlServer.Hosting
You can now use an option class in Akka.Persistence.SqlServer.Hosting to replace HOCON configuration fully.
Add Akka.Hosting.TestKit
module
The biggest difference between Akka.Hosting.TestKit and Akka.TestKit is that, since the test is started asynchronously, the TestKit properties and methods would not be available in the unit test class constructor anymore. Since the spec depends on Microsoft HostBuilder
, configuration has to be broken down into steps. There are overridable methods that user can use to override virtually all of the setup process.
These are steps of what overridable methods gets called. Not all of the methods needs to be overriden, at the minimum, if you do not need a custom hosting environment, you need to override the ConfigureAkka
method.
-
ConfigureLogging(ILoggingBuilder)
Add custom logger and filtering rules on the
HostBuilder
level. -
ConfigureHostConfiguration(IConfigurationBuilder)
Inject any additional hosting environment configuration here, such as faking environment variables, in the
HostBuilder
level. -
ConfigureAppConfiguration(HostBuilderContext, IConfigurationBuilder)
Inject the application configuration.
-
ConfigureServices(HostBuilderContext, IServiceCollection)
Add additional services needed by the test, such as mocked up services used inside the dependency injection.
-
User defined HOCON configuration is injected by overriding the
Config
property, it is not passed as part of the constructor anymore. -
ConfigureAkka(AkkaConfigurationBuilder, IServiceProvider)
This is called inside
AddAkka
, use this to configure theAkkaConfigurationBuilder
-
BeforeTestStart()
This method is called after the TestKit is initialized. Move all of the codes that used to belong in the constructor here.
Akka.Hosting.TestKit
extends Akka.TestKit.TestKitBase
directly, all testing methods are available out of the box.
All of the properties, such as Sys
and TestActor
will be available once the unit test class is invoked.
Add a standardized option code pattern for Akka.Hosting developer
This new feature is intended for Akka.Hosting module developer only, it is used to standardize how Akka.Hosting addresses a very common HOCON configuration pattern. This allows for a HOCON-less programmatic setup replacement for the HOCON path used to configure the HOCON property.
The pattern:
# This HOCON property references to a config block below
akka.discovery.method = akka.discovery.config
akka.discovery.config {
class = "Akka.Discovery.Config.ConfigServiceDiscovery, Akka.Discovery"
# other options goes here
}
Example implementation:
// The base class for the option, needs to implement the IHoconOption template interface
public abstract class DiscoveryOptionBase : IHoconOption
{ }
// The actual option implementation
public class ConfigOption : DiscoveryOptionBase
{
// The path value in the akka.discovery.method property above
public string ConfigPath => "akka.discovery.config";
// The FQCN value in the akka.discovery.config.class property above
public Type Class => typeof(ConfigServiceDiscovery);
// Generate the same HOCON config as above
public void Apply(AkkaConfigurationBuilder builder, Setup setup = null)
{
// Modifies Akka.NET configuration either via HOCON or setup class
builder.AddHocon(
$"akka.discovery.method = {ConfigPath.ToHocon()}",
HoconAddMode.Prepend);
builder.AddHocon($"akka.discovery.config.class = {
Class.AssemblyQualifiedName.ToHocon()}",
HoconAddMode.Prepend);
// Rest of configuration goes here
}
}
// Akka.Hosting extension implementation
public static AkkaConfigurationBuilder WithDiscovery(
this AkkaConfigurationBuilder builder,
DiscoveryOptionBase discOption)
{
var setup = new DiscoverySetup();
// gets called here
discOption.Apply(builder, setup);
}
0.4.3
0.4.2
0.4.1
• Fix Microsoft.Extensions.Logging.ILoggerFactory logging support
• Add InMemory snapshot store and journal persistence support
Due to a bad API design, we're rolling back the Microsoft.Extensions.Logging.ILoggerFactory
logger support introduced in version 0.4.0, the 0.4.0 NuGet version is now considered as deprecated in support of the new API design introduced in version 0.4.1.
Logger Configuration Support
You can now use the new AkkaConfigurationBuilder
extension method called ConfigureLoggers(Action<LoggerConfigBuilder>)
to configure how Akka.NET logger behave.
Example:
builder.Services.AddAkka("MyActorSystem", configurationBuilder =>
{
configurationBuilder
.ConfigureLoggers(setup =>
{
// Example: This sets the minimum log level
setup.LogLevel = LogLevel.DebugLevel;
// Example: Clear all loggers
setup.ClearLoggers();
// Example: Add the default logger
// NOTE: You can also use setup.AddLogger<DefaultLogger>();
setup.AddDefaultLogger();
// Example: Add the ILoggerFactory logger
// NOTE:
// - You can also use setup.AddLogger<LoggerFactoryLogger>();
// - To use a specific ILoggerFactory instance, you can use setup.AddLoggerFactory(myILoggerFactory);
setup.AddLoggerFactory();
// Example: Adding a serilog logger
setup.AddLogger<SerilogLogger>();
})
.WithActors((system, registry) =>
{
var echo = system.ActorOf(act =>
{
act.ReceiveAny((o, context) =>
{
Logging.GetLogger(context.System, "echo").Info($"Actor received {o}");
context.Sender.Tell($"{context.Self} rcv {o}");
});
}, "echo");
registry.TryRegister<Echo>(echo); // register for DI
});
});
A complete code sample can be viewed here.
Exposed properties are:
LogLevel
: Configure the Akka.NET minimum log level filter, defaults toInfoLevel
LogConfigOnStart
: When set to true, Akka.NET will log the complete HOCON settings it is using at start up, this can then be used for debugging purposes.
Currently supported logger methods:
ClearLoggers()
: Clear all registered logger types.AddLogger<TLogger>()
: Add a logger type by providing its class type.AddDefaultLogger()
: Add the default Akka.NET console logger.AddLoggerFactory()
: Add the newILoggerFactory
logger.
Microsoft.Extensions.Logging.ILoggerFactory Logging Support
You can now use ILoggerFactory
from Microsoft.Extensions.Logging as one of the sinks for Akka.NET logger. This logger will use the ILoggerFactory
service set up inside the dependency injection ServiceProvider
as its sink.
Microsoft.Extensions.Logging Log Event Filtering
There will be two log event filters acting on the final log input, the Akka.NET akka.loglevel
setting and the Microsoft.Extensions.Logging
settings, make sure that both are set correctly or some log messages will be missing.
To set up the Microsoft.Extensions.Logging
log filtering, you will need to edit the appsettings.json
file. Note that we also set the Akka
namespace to be filtered at debug level in the example below.
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information",
"Akka": "Debug"
}
}
}
InMemory Snapshot Store And Journal Support
You can now use these AkkaConfigurationBuilder
extension methods to enable InMemory
persistence back end:
WithInMemoryJournal()
: Sets theInMemory
journal as the default journal persistence pluginWithInMemorySnapshotStore()
: Sets theInMemory
snapshot store as the default snapshot-store persistence plugin.
0.4.0
• Add Microsoft.Extensions.Logging.ILoggerFactory logging support
You can now use ILoggerFactory
from Microsoft.Extensions.Logging as one of the sinks for Akka.NET logger. This logger will use the ILoggerFactory
service set up inside the dependency injection ServiceProvider
as its sink.
Example:
builder.Services.AddAkka("MyActorSystem", (configurationBuilder, serviceProvider) =>
{
configurationBuilder
.AddHocon("akka.loglevel = DEBUG")
.WithLoggerFactory()
.WithActors((system, registry) =>
{
var echo = system.ActorOf(act =>
{
act.ReceiveAny((o, context) =>
{
Logging.GetLogger(context.System, "echo").Info($"Actor received {o}");
context.Sender.Tell($"{context.Self} rcv {o}");
});
}, "echo");
registry.TryRegister<Echo>(echo); // register for DI
});
});
There are two Akka.Hosting
extension methods provided:
.WithLoggerFactory()
: Replaces all Akka.NET loggers with the newILoggerFactory
logger..AddLoggerFactory()
: Inserts the newILoggerFactory
logger into the Akka.NET logger list.
Log Event Filtering
There will be two log event filters acting on the final log input, the Akka.NET akka.loglevel
setting and the Microsoft.Extensions.Logging
settings, make sure that both are set correctly or some log messages will be missing.
To set up the Microsoft.Extensions.Logging
log filtering, you will need to edit the appsettings.json
file. Note that we also set the Akka
namespace to be filtered at debug level in the example below.
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information",
"Akka": "Debug"
}
}
}
0.3.4
0.3.3
• Added common Akka.Persistence.Hosting package to make it easier to add IEventAdapters to journals.
• Made Akka.Persistence.SqlServer.Hosting and Akka.Persistence.PostgreSql.Hosting both take a shared overload / dependency on Akka.Persistence.Hosting • did this to make it easier to add IEventAdapters to each of those.
• Add Akka.Cluster.Tools.Client support • now possible to start ClusterClient and ClusterClientReceptionists easily from Akka.Hosting.