Skip to content

Releases: akkadotnet/Akka.Hosting

0.5.1

20 Oct 19:47
1030d84
Compare
Choose a tag to compare

0.5.0

04 Oct 18:11
d942b8e
Compare
Choose a tag to compare

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.

  1. ConfigureLogging(ILoggingBuilder)

    Add custom logger and filtering rules on the HostBuilder level.

  2. ConfigureHostConfiguration(IConfigurationBuilder)

    Inject any additional hosting environment configuration here, such as faking environment variables, in the HostBuilder level.

  3. ConfigureAppConfiguration(HostBuilderContext, IConfigurationBuilder)

    Inject the application configuration.

  4. ConfigureServices(HostBuilderContext, IServiceCollection)

    Add additional services needed by the test, such as mocked up services used inside the dependency injection.

  5. User defined HOCON configuration is injected by overriding the Config property, it is not passed as part of the constructor anymore.

  6. ConfigureAkka(AkkaConfigurationBuilder, IServiceProvider)

    This is called inside AddAkka, use this to configure the AkkaConfigurationBuilder

  7. 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

10 Sep 15:22
5ebc39b
Compare
Choose a tag to compare

0.4.2

12 Aug 00:33
293e5a9
Compare
Choose a tag to compare

0.4.1

21 Jul 17:14
a52690c
Compare
Choose a tag to compare

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 to InfoLevel
  • 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 new ILoggerFactory 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 the InMemory journal as the default journal persistence plugin
  • WithInMemorySnapshotStore(): Sets the InMemory snapshot store as the default snapshot-store persistence plugin.

0.4.0

18 Jul 20:29
2f1683d
Compare
Choose a tag to compare

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 new ILoggerFactory logger.
  • .AddLoggerFactory(): Inserts the new ILoggerFactory 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

23 Jun 18:43
658c491
Compare
Choose a tag to compare

0.3.3

16 Jun 17:48
67776ce
Compare
Choose a tag to compare

0.3.2

13 Jun 16:48
e1f3317
Compare
Choose a tag to compare

0.3.1

09 Jun 14:44
ed718fd
Compare
Choose a tag to compare