Code Monkey home page Code Monkey logo

akka.interfaced's Introduction

Akka.Interfaced

NuGet Status Build status Coverage Status Coverity Status

Akka.Interfaced provides the type-safe and declarative way for actor communicating on Akka.NET. This project is influenced by WCF Contract and Orleans.

Example

For the first time, we need to design the interface of a greeting actor. Greeting actor can greet and it can count how much it say hello. Defining the interface IGreeter to show the way the actor communicate is natural for C# programmers.

public interface IGreeter : IInterfacedActor
{
    Task<string> Greet(string name);
    Task<int> GetCount();
}

After defining interface, it's time to define the class implementing IGreeter, GreetingActor. It should inherit InterfacedActor because it's an Akka.NET actor. Implementing IGreeter interface is a bit simple.

public class GreetingActor : InterfacedActor, IGreeter
{
    private int _count;

    Task<string> IGreeter.Greet(string name)
    {
        _count += 1;
        return Task.FromResult($"Hello {name}!");
    }

    Task<int> IGreeter.GetCount()
    {
        return Task.FromResult(_count);
    }
}

We designed interface and implemented the actor. Finally we can send a message to and get a reply from GreetingActor actor by using GreeterRef. GreeterRef implements IGreeter, you can get IGreeter instance from GreeterRef and use it as a regular C# interface.

async Task TestAsync(ActorSystem system)
{
    // Create GreetingActor and make a reference pointing to an actor.
    var actor = system.ActorOf<GreetingActor>();
    var greeter = new GreeterRef(actor);

    // Make some noise
    Console.WriteLine(await greeter.Greet("World")); // Output: Hello World!
    Console.WriteLine(await greeter.Greet("Actor")); // Output: Hello Actor!
    Console.WriteLine(await greeter.GetCount());     // Output: 2
}

Where can I get it?

Common projects using Akka.Interfaceds consist of at least two projects. One is an interface project defining interfaces such as previous IGreeter and the other is a main project defining the rest such as previous GreetingActor.

For an interface project:

PM> Install-Package Akka.Interfaced.Templates

For a main project:

PM> Install-Package Akka.Interfaced

For a detailed explanation, read Project configuration.

Manual

Comprehensive manual for using Akka.Interfaced: Manual

akka.interfaced's People

Contributors

veblush avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.