Convert Figma logo to code with AI

akkadotnet logoakka.net

Canonical actor model implementation for .NET with local + distributed actors in C# and F#.

4,686
1,040
4,686
405

Top Related Projects

23,812

Dapr is a portable, event-driven, runtime for building distributed applications across cloud and edge.

Service Fabric is a distributed systems platform for packaging, deploying, and managing stateless and stateful distributed applications and containers at large scale.

2,383

[Archived] Incredibly simple real-time web for ASP.NET Core. Project moved to https://github.com/aspnet/AspNetCore

41,549

The C based gRPC (C++, Python, Ruby, Objective-C, PHP, C#)

Quick Overview

Akka.NET is a toolkit and runtime for building highly concurrent, distributed, and fault-tolerant event-driven applications on .NET. It is an open-source port of the popular Akka framework from the Java/Scala world, bringing the actor model and its benefits to the .NET ecosystem.

Pros

  • Simplifies building scalable and resilient distributed systems
  • Provides a high-level abstraction for concurrent programming with actors
  • Offers built-in support for clustering and remoting
  • Includes patterns for fault tolerance and self-healing systems

Cons

  • Steep learning curve for developers new to the actor model
  • Can be overkill for simple applications or small-scale projects
  • Limited ecosystem compared to its JVM counterpart
  • Requires careful design to avoid common pitfalls in actor-based systems

Code Examples

  1. Creating a simple actor:
public class GreetingActor : ReceiveActor
{
    public GreetingActor()
    {
        Receive<string>(message => Console.WriteLine($"Hello, {message}!"));
    }
}
  1. Sending a message to an actor:
var system = ActorSystem.Create("MySystem");
var greeter = system.ActorOf<GreetingActor>("greeter");
greeter.Tell("World");
  1. Implementing actor supervision:
public class SupervisorActor : ReceiveActor
{
    public SupervisorActor()
    {
        var child = Context.ActorOf(Props.Create<ChildActor>(), "child");
        Receive<string>(message => child.Forward(message));
    }

    protected override SupervisorStrategy SupervisorStrategy()
    {
        return new OneForOneStrategy(
            maxNrOfRetries: 10,
            withinTimeRange: TimeSpan.FromMinutes(1),
            localOnlyDecider: ex =>
            {
                switch (ex)
                {
                    case ArgumentException ae:
                        return Directive.Resume;
                    default:
                        return Directive.Restart;
                }
            });
    }
}

Getting Started

To get started with Akka.NET, follow these steps:

  1. Install the NuGet package:

    dotnet add package Akka
    
  2. Create an actor system and an actor:

    using Akka.Actor;
    
    var system = ActorSystem.Create("MySystem");
    var myActor = system.ActorOf<MyActor>("myActor");
    
  3. Send messages to the actor:

    myActor.Tell("Hello, Akka.NET!");
    
  4. Remember to shut down the actor system when you're done:

    await system.Terminate();
    

For more detailed information and advanced usage, refer to the official Akka.NET documentation.

Competitor Comparisons

23,812

Dapr is a portable, event-driven, runtime for building distributed applications across cloud and edge.

Pros of Dapr

  • Language-agnostic, supporting multiple programming languages and frameworks
  • Modular architecture with pluggable components for various cloud services
  • Designed for both Kubernetes and standalone deployments

Cons of Dapr

  • Relatively newer project with a smaller community compared to Akka.NET
  • Requires additional setup and infrastructure components
  • Learning curve for developers unfamiliar with microservices architecture

Code Comparison

Dapr (using HTTP API):

import requests

# Invoke a method on another service
requests.post('http://localhost:3500/v1.0/invoke/myapp/method/hello', json={'name': 'World'})

Akka.NET:

var actor = ActorSystem.Create("MySystem").ActorOf<HelloActor>();
actor.Tell(new HelloMessage("World"));

Summary

Dapr offers a more flexible, language-agnostic approach to building distributed applications, while Akka.NET provides a mature, actor-based model specifically for .NET developers. Dapr's modular architecture allows for easier integration with various cloud services, but it may require more setup and infrastructure. Akka.NET, on the other hand, offers a more straightforward development experience within the .NET ecosystem but with less flexibility across different languages and platforms.

Service Fabric is a distributed systems platform for packaging, deploying, and managing stateless and stateful distributed applications and containers at large scale.

Pros of Service Fabric

  • Comprehensive microservices platform with built-in orchestration and management
  • Seamless integration with Azure services and cloud-native features
  • Strong support for stateful services and actor model programming

Cons of Service Fabric

  • Steeper learning curve due to its complex architecture and concepts
  • Primarily designed for Windows and Azure environments, limiting cross-platform usage
  • Less flexibility in deployment options compared to Akka.NET

Code Comparison

Service Fabric (C#):

public class MyStatefulService : StatefulService
{
    protected override async Task RunAsync(CancellationToken cancellationToken)
    {
        // Service logic here
    }
}

Akka.NET (C#):

public class MyActor : ReceiveActor
{
    public MyActor()
    {
        Receive<string>(message => HandleMessage(message));
    }
}

Both frameworks provide abstractions for building distributed systems, but Service Fabric focuses on a more comprehensive microservices platform, while Akka.NET emphasizes the actor model for concurrent and distributed programming. Service Fabric offers tighter integration with Azure services, whereas Akka.NET provides more flexibility in terms of deployment options and cross-platform support.

2,383

[Archived] Incredibly simple real-time web for ASP.NET Core. Project moved to https://github.com/aspnet/AspNetCore

Pros of SignalR

  • Simpler to set up and use for real-time web applications
  • Tighter integration with ASP.NET Core ecosystem
  • Automatic fallback to long polling if WebSockets are not available

Cons of SignalR

  • Limited to .NET ecosystem, less flexible for polyglot environments
  • Less suitable for complex distributed systems and actor-based architectures
  • Fewer built-in patterns for fault tolerance and scalability

Code Comparison

SignalR:

public class ChatHub : Hub
{
    public async Task SendMessage(string user, string message)
    {
        await Clients.All.SendAsync("ReceiveMessage", user, message);
    }
}

Akka.NET:

public class ChatActor : ReceiveActor
{
    public ChatActor()
    {
        Receive<SendMessage>(msg => HandleSendMessage(msg));
    }

    private void HandleSendMessage(SendMessage msg)
    {
        // Broadcast message to all connected clients
    }
}

SignalR is more straightforward for simple real-time communication scenarios, while Akka.NET provides a more robust actor-based model for complex distributed systems. SignalR integrates seamlessly with ASP.NET Core, making it easier for .NET developers to add real-time features to web applications. Akka.NET, on the other hand, offers greater flexibility and scalability for building distributed systems across multiple platforms and languages.

41,549

The C based gRPC (C++, Python, Ruby, Objective-C, PHP, C#)

Pros of gRPC

  • Language-agnostic: Supports multiple programming languages out of the box
  • High performance: Utilizes HTTP/2 for efficient communication
  • Strong typing: Uses Protocol Buffers for serialization and type safety

Cons of gRPC

  • Steeper learning curve: Requires understanding of Protocol Buffers and gRPC concepts
  • Limited browser support: Not natively supported in web browsers without additional tools

Code Comparison

Akka.NET (Actor-based approach):

public class MyActor : ReceiveActor
{
    public MyActor()
    {
        Receive<string>(message => Console.WriteLine($"Received: {message}"));
    }
}

gRPC (RPC-based approach):

service Greeter {
  rpc SayHello (HelloRequest) returns (HelloReply) {}
}
message HelloRequest {
  string name = 1;
}

Summary

While Akka.NET focuses on actor-based concurrency and distributed systems, gRPC specializes in efficient, language-agnostic remote procedure calls. Akka.NET provides a more comprehensive framework for building scalable and resilient systems, while gRPC excels in high-performance, cross-language communication. The choice between the two depends on specific project requirements, such as the need for actor-based programming or language interoperability.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Akka.NET

Akka.NET logo

Discord NuGet Nuget

Akka.NET is a .NET port of the popular Akka project from the Scala / Java community. We are an idiomatic .NET implementation of the actor model built on top of the .NET Common Language Runtime.

Akka.NET is a .NET Foundation project.

.NET Foundation Logo

How is Akka.NET Used?

Akka.NET can be used in-process or inside large, distributed real-time systems; we support a wide variety of use cases.

Akka.NET can be used to solve the following types of problems:

  1. Concurrency - Akka.NET actors only process messages one-at-a-time and they do so in first in, first out (FIFO) order; this means that any application state internal to an actor is automatically thread-safe without having to use locks or any other shared-memory synchronization mechanisms.
  2. Stream Processing - Akka.NET actors and Akka.Streams make it easy to build streaming applications, used for processing incoming streams of data or incoming streams of live events such as UI or network events inside native applications.
  3. Event-Driven Programming - actors make it easy to build event-driven applications, as actors' message-processing routines naturally express these types of designs.
  4. Event Sourcing and CQRS - Akka.Persistence, used by actors to make their state re-entrant and recoverable across restarts or migrations between nodes, natively supports event sourcing. Akka.Persistence.Query can be used to compute CQRS-style projections and materialized views from Akka.Persistence data.
  5. Location Transparency - Akka.Remote makes it simple for actors in remote processes to transparently communicate with each other.
  6. Highly Available, Fault-Tolerant Distributed Systems - Akka.Cluster, Akka.Cluster.Sharding, and other tools built on top of Akka.Cluster make it possible to build highly available and fault-tolerant distributed systems by leveraging peer-to-peer programming models with topology-aware message routing and distribution.
  7. Low Latency, High Throughput - Akka.NET aims to be low latency and high throughput, processing 10s millions of messages per second in-memory and hundreds of thousands of messages per second over remote connections.

Where Can I Learn Akka.NET?

You can start by taking the Akka.NET Bootcamp, but there are many other great learning resources for Akka.NET Online.

Build Status

StageStatus
BuildBuild Status
NuGet PackBuild Status
.NET Framework Unit TestsBuild Status
.NET Unit Tests (Windows)Build Status
.NET Unit Tests (Linux)Build Status
.NET MultiNode Tests (Windows)Build Status
.NET MultiNode Tests (Linux)Build Status
DocsBuild Status

Install Akka.NET via NuGet

If you want to include Akka.NET in your project, you can install it directly from NuGet

To install Akka.NET Distributed Actor Framework, run the following command in the Package Manager Console

PM> Install-Package Akka.Hosting

Akka.Hosting includes the base Akka NuGet package and also provides an easy interface to integrate Akka.NET with the most-used parts of the Microsoft.Extensions ecosystem: Configuration, Logging, Hosting, and DependencyInjection. We encourage developers to adopt it.

And if you need F# support:

PM> Install-Package Akka.FSharp

Akka.NET Project Templates

To create your own Akka.NET projects using our templates (Akka.Templates), install them via the dotnet CLI:

dotnet new install "Akka.Templates::*"

This will make our templates available via dotnet new on the CLI and as new project templates inside any .NET IDE such as Visual Studio or JetBrains Rider. You can view the full list of templates included in our package here: https://github.com/akkadotnet/akkadotnet-templates#available-templates

Builds

Please see Building Akka.NET.

To access nightly Akka.NET builds, please see the instructions here.

Support

If you need help getting started with Akka.NET, there's a number of great community resources online:

If you and your company are interested in getting professional Akka.NET support, you can contact Petabridge for dedicated Akka.NET support.