Git Product home page Git Product logo

akka-typed-by-examples's Introduction

AKKA 2.6 By examples

I'm starting to migrate a few projects to AKKA 2.6 from AKKA 2.*. The idea is to start using the new (and looks like now more mature) Akka Typed.

So I will use this repo to try the migration in a small project before to go ahead with the others.

This is a continuation of the Migrating/Comparision from Akka Classic to Typed but removing the Classic implementation part.

Current state of this project covers:

  • Akka gRPC
  • Akka Typed
  • Akka Event Sourcing
  • Akka Persistence
  • Akka Stream Typed

Posts covering every part:

Services description

Remind that the idea of this service is not to implement something cool but something to play with Akka Typed style.

So the functionality is really simple:

Server.

The server is a Counter service. It is going to keep the counter in the service along with the number of events created.

This is the list of services to expose:

  • Inc will increment the counter the X times and increment one time the events counter.
  • Incs like Inc service but in a streaming way.
  • Get will return the counter and the number of events generated.

The definition is in the submodule protobuf-api

Client.

The client will stimulate the counter in different ways to play with, for example, back-pressure.

Running

From the project root:

Assembly the project.

sbt clean universal:packageZipTarball

Server side

The server is using typesafe config configuration system, so it is possible to override all configuration:

  • server.interface = interface binding. Default 0.0.0.0 so listening from everywhere.
  • server.port = Port listening. Default 8080

Running setting, for example, the server interface to listen:

bin/server -Dserver.interface=localhost

Client side

The implementation is using the Akka gRPC like the server, so it is using typesafe config configuration system.

  • akka.grpc.client.example.api.CounterService.host = Server host. Default locahost
  • akka.grpc.client.example.api.CounterService.port = Server port. Default 8080

Three different behaviors depending on the number of parameters:

  • No parameters: Return the counter and the number of events generated.
  • One parameter: Increment the counter X times.
  • Two parameters: Execute the previous one as a stream, calling the service one time every value in the range.

Increment 10 with defaults

bin/client 10

Example:

In on terminal, execute the server:

$ bin/server
[2019-11-16 17:14:23,252] [INFO] [akka.event.slf4j.Slf4jLogger] [CounterServer-akka.actor.default-dispatcher-6] [] - Slf4jLogger started
[2019-11-16 17:14:23,366] [WARN] [akka.persistence.Persistence] [CounterServer-akka.actor.default-dispatcher-9] [Persistence(akka://CounterServer)] - No default snapshot store configured! To configure a default snapshot-store plugin set the `akka.persistence.snapshot-store.plugin` key. For details see 'reference.conf'
Counter server typed online at http://0:0:0:0:0:0:0:0:8080/

In other terminal, execute the client:

$ bin/client
Current state: Accumulator [0] / Events executed [0].

$ bin/client 10
Successfully incremented.

$ bin/client
Current state: Accumulator [10] / Events executed [1].

$ bin/client 5 10
Incremented Done()
Incremented Done()
Incremented Done()
Incremented Done()
Incremented Done()
Incremented Done()
Incremented range [Range 5 to 10].

$ bin/client
Current state: Accumulator [55] / Events executed [7].

Future

In the future, I will use this project to do add:

  • Clustering
  • Sharding

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.