Actor System
Overview
Example
package main
import (
"context"
"os"
"os/signal"
"sync"
"syscall"
"time"
"github.com/tochemey/goakt/v3/actor"
"github.com/tochemey/goakt/v3/log"
)
func main() {
ctx := context.Background()
host := "0.0.0.0"
port := 4000
logger := log.New(log.InfoLevel, os.Stdout)
// create an actor system. Check the reference
// doc for additional options
actorSystem, err := actor.NewActorSystem(
"ChatSystem",
actor.WithPassivationDisabled(),
actor.WithRemoting(host, int32(port)),
actor.WithLogger(logger))
if err != nil {
logger.Fatal(err)
os.Exit(1)
}
// start the actor system
if err := actorSystem.Start(ctx); err != nil {
logger.Fatal(err)
os.Exit(1)
}
// capture ctrl+c
interruptSignal := make(chan os.Signal, 1)
signal.Notify(interruptSignal, os.Interrupt, syscall.SIGINT, syscall.SIGTERM)
<-interruptSignal
// stop the actor system
_ = actorSystem.Stop(ctx)
os.Exit(0)
}
Characteristics
Last updated