An actor framework for Go

Go Report Card

gosiris is an actor framework for Golang.

Features

  • Manage a hierarchy of actors (each actor has its own: state, behavior, mailbox, child actors)
  • Deploy remote actors accessible though an AMQP broker or Kafka
  • Automated registration and runtime discoverability using etcd registry
  • Zipkin integration
  • Built-in patterns (become/unbecome, send, forward, repeat, child supervision)

Examples

Hello world

package main

import (
	"gosiris/gosiris"
)

func main() {
	//Init a local actor system
	gosiris.InitActorSystem(gosiris.SystemOptions{
		ActorSystemName: "ActorSystem",
	})

	//Create an actor
	parentActor := gosiris.Actor{}
	//Close an actor
	defer parentActor.Close()

	//Create an actor
	childActor := gosiris.Actor{}
	//Close an actor
	defer childActor.Close()
	//Register a reaction to event types ("message" in this case)
	childActor.React("message", func(context gosiris.Context) {
		context.Self.LogInfo(context, "Received %v\n", context.Data)
	})

	//Register an actor to the system
	gosiris.ActorSystem().RegisterActor("parentActor", &parentActor, nil)
	//Register an actor by spawning it
	gosiris.ActorSystem().SpawnActor(&parentActor, "childActor", &childActor, nil)

	//Retrieve actor references
	parentActorRef, _ := gosiris.ActorSystem().ActorOf("parentActor")
	childActorRef, _ := gosiris.ActorSystem().ActorOf("childActor")

	//Send a message from one actor to another (from parentActor to childActor)
	childActorRef.Tell(gosiris.EmptyContext, "message", "Hi! How are you?", parentActorRef)
}
INFO: [childActor] 1988/01/08 01:00:00 Received Hi! How are you?

Distributed actor system example

In the following example, in less than 30 effective lines of code, we will see how to create a distributed actor system implementing a request/reply interaction. An actor will be triggered by AMQP messages while another one will be triggered by Kafka events. Each actor will register itself in an etcd instance and will discover the other actor at runtime. Last but not least, gosiris will also manage the Zipkin integration by automatically managing the spans and forwarding the logs.

package main

import (
	"gosiris/gosiris"
	"time"
)

func main() {
	//Configure a distributed actor system with an etcd registry and a Zipkin integration
	gosiris.InitActorSystem(gosiris.SystemOptions{
		ActorSystemName: "ActorSystem",
		RegistryUrl:     "http://etcd:2379",
		ZipkinOptions: gosiris.ZipkinOptions{
			Url:      "http://zipkin:9411/api/v1/spans",
			Debug:    true,
			HostPort: "0.0.0.0",
			SameSpan: true,
		},
	})
	//Defer the actor system closure
	defer gosiris.CloseActorSystem()

	//Configure actor1
	actor1 := new(gosiris.Actor).React("reply", func(context gosiris.Context) {
		//Because Zipkin is enabled, the log will be also sent to the Zipkin server
		context.Self.LogInfo(context, "Received: %v", context.Data)

	})
	//Defer actor1 closure
	defer actor1.Close()
	//Register a remote actor accessible through AMQP
	gosiris.ActorSystem().RegisterActor("actor1", actor1, new(gosiris.ActorOptions).SetRemote(true).SetRemoteType(gosiris.Amqp).SetUrl("amqp://guest:guest@amqp:5672/").SetDestination("actor1"))

	//Configure actor2
	actor2 := new(gosiris.Actor).React("context", func(context gosiris.Context) {
		//Because Zipkin is enabled, the log will be also sent to the Zipkin server
		context.Self.LogInfo(context, "Received: %v", context.Data)
		context.Sender.Tell(context, "reply", "hello back", context.Self)
	})
	//Defer actor2 closure
	defer actor2.Close()
	//Register a remote actor accessible through Kafka
	gosiris.ActorSystem().SpawnActor(actor1, "actor2", actor2, new(gosiris.ActorOptions).SetRemote(true).SetRemoteType(gosiris.Kafka).SetUrl("kafka:9092").SetDestination("actor2"))

	//Retrieve the actor references
	actor1Ref, _ := gosiris.ActorSystem().ActorOf("actor1")
	actor2Ref, _ := gosiris.ActorSystem().ActorOf("actor2")

	//Send a message to the kafkaRef
	actor2Ref.Tell(gosiris.EmptyContext, "context", "hello", actor1Ref)

	time.Sleep(250 * time.Millisecond)
}
INFO: [actor2] 2017/11/11 00:38:24 Received: hello
INFO: [actor1] 2017/11/11 00:38:24 Received: hello back

More Examples

See the examples in actor_test.go.

Environment

First of all, to run the examples you must configure the following hostnames: etcd, amqp, zipkin, and kafka. Then to setup the full environment, you can simply run the Docker Compose.

Troubleshooting

You may experience errors during the tests like the following:

r.EncodeArrayStart undefined (type codec.encDriver has no field or method EncodeArrayStart)

This is a known issue with the etcd client used. The manual workaround (for the time being) is to delete manually the file keys.generated.go generated in /vendor.

Contributing

  • Open an issue if you want a new feature or if you spotted a bug
  • Feel free to propose pull requests

Any contribution is more than welcome! In the meantime, if we want to discuss gosiris you can contact me @teivah.

Owner
Teiva Harsanyi
Software Engineer, Go, Rust, Java | @ReactiveX​/​RxGo | 改善
Teiva Harsanyi
Similar Resources

If I were a malicious actor, how would I sneak my code in?

go-error-hijack-poc This repo demonstrates a hypothetical use of sentinel errors and horizontally off-screen code as attack vectors. How to Run Run th

Jan 15, 2022

7 days golang programs from scratch (web framework Gee, distributed cache GeeCache, object relational mapping ORM framework GeeORM, rpc framework GeeRPC etc) 7天用Go动手写/从零实现系列

7 days golang programs from scratch README 中文版本 7天用Go从零实现系列 7天能写什么呢?类似 gin 的 web 框架?类似 groupcache 的分布式缓存?或者一个简单的 Python 解释器?希望这个仓库能给你答案

Jan 5, 2023

Flamingo Framework and Core Library. Flamingo is a go based framework for pluggable web projects. It is used to build scalable and maintainable (web)applications.

Flamingo Framework and Core Library. Flamingo is a go based framework for pluggable web projects. It is used to build scalable and maintainable (web)applications.

Flamingo Framework Flamingo is a web framework based on Go. It is designed to build pluggable and maintainable web projects. It is production ready, f

Jan 5, 2023

Golanger Web Framework is a lightweight framework for writing web applications in Go.

/* Copyright 2013 Golanger.com. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except

Nov 14, 2022

Flamingo Framework and Core Library. Flamingo is a go based framework for pluggable web projects. It is used to build scalable and maintainable (web)applications.

Flamingo Framework and Core Library. Flamingo is a go based framework for pluggable web projects. It is used to build scalable and maintainable (web)applications.

Flamingo Framework Flamingo is a web framework based on Go. It is designed to build pluggable and maintainable web projects. It is production ready, f

Jan 5, 2023

Golanger Web Framework is a lightweight framework for writing web applications in Go.

/* Copyright 2013 Golanger.com. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except

Nov 14, 2022

GoCondor is a golang web framework with an MVC like architecture, it's based on Gin framework

GoCondor is a golang web framework with an MVC like architecture, it's based on Gin framework

GoCondor is a golang web framework with an MVC like architecture, it's based on Gin framework, it features a simple organized directory structure for your next project with a pleasant development experience, made for developing modern APIs and microservices.

Dec 29, 2022

The jin is a simplified version of the gin web framework that can help you quickly understand the core principles of a web framework.

jin About The jin is a simplified version of the gin web framework that can help you quickly understand the core principles of a web framework. If thi

Jul 14, 2022

laravel for golang,goal,fullstack framework,api framework

laravel for golang,goal,fullstack framework,api framework

laravel for golang,goal,fullstack framework,api framework

Feb 24, 2022

Rpcx-framework - An RPC microservices framework based on rpcx, simple and easy to use, ultra fast and efficient, powerful, service discovery, service governance, service layering, version control, routing label registration.

RPCX Framework An RPC microservices framework based on rpcx. Features: simple and easy to use, ultra fast and efficient, powerful, service discovery,

Jan 5, 2022

terraform-plugin-mux Example (framework + framework)

Terraform Provider Scaffolding (Terraform Plugin Framework) This template repository is built on the Terraform Plugin Framework. The template reposito

Feb 8, 2022

Gin is a HTTP web framework written in Go (Golang).

Gin is a HTTP web framework written in Go (Golang).

Gin is a HTTP web framework written in Go (Golang). It features a Martini-like API with much better performance -- up to 40 times faster. If you need smashing performance, get yourself some Gin.

Jan 3, 2023

Simple yet customizable bot framework written in Go.

Simple yet customizable bot framework written in Go.

Introduction Sarah is a general-purpose bot framework named after the author's firstborn daughter. This comes with a unique feature called "stateful c

Dec 12, 2022

Golang Framework for writing Slack bots

hanu - Go for Slack Bots! The Go framework hanu is your best friend to create Slack bots! hanu uses allot for easy command and request parsing (e.g. w

Oct 24, 2022

Telegram Bot Framework for Go

Margelet Telegram Bot Framework for Go is based on telegram-bot-api It uses Redis to store it's states, configs and so on. Any low-level interactions

Dec 22, 2022

Slack Bot Framework

slacker Built on top of the Slack API github.com/slack-go/slack with the idea to simplify the Real-Time Messaging feature to easily create Slack Bots,

Dec 25, 2022

Slack bot core/framework written in Go with support for reactions to message updates/deletes

Slack bot core/framework written in Go with support for reactions to message updates/deletes

Overview Requirements Features Demo The Name Concepts Create Your Own Slackscot Assembling the Parts and Bringing Your slackscot to Life Configuration

Oct 28, 2022

Telebot is a Telegram bot framework in Go.

Telebot "I never knew creating Telegram bots could be so sexy!" go get -u gopkg.in/tucnak/telebot.v2 Overview Getting Started Poller Commands Files Se

Dec 30, 2022

Another CLI framework for Go. It works on my machine.

Another CLI framework for Go. It works on my machine.

Command line interface framework Go framework for rapid command line application development

Dec 30, 2022
Comments
  • * a proposal for the implementation of the ASK pattern (like in Akka)

    * a proposal for the implementation of the ASK pattern (like in Akka)

    please consider this a suggestion/work_in_progress :) I just started learning Go, and for a personal project I found I needed the Ask pattern that is present in Akka... so here's a possible implemenation of it. This is useful when you want to extract data from an actor, from outside the actorsystem. An example is in the actor_test.go file, the "asked" actor should reply by "Tell"ing the sender using the same messageType string.

    Any feedback is greatly appreciated :)

  • zipkin-related build issue

    zipkin-related build issue

    I got this error while running go build when trying to run the helloworld example

    source.golabs.io/growth/actor-model-demo/vendor/github.com/openzipkin/zipkin-go-opentracing/_thrift/gen-go/scribe

    vendor/github.com/openzipkin/zipkin-go-opentracing/_thrift/gen-go/scribe/scribe.go:101:15: cannot assign 1 values to 2 variables

    vendor/github.com/openzipkin/zipkin-go-opentracing/_thrift/gen-go/scribe/scribe.go:147:28: cannot use scribeProcessorLog literal (type *scribeProcessorLog) as type thrift.TProcessorFunction in assignment: *scribeProcessorLog does not implement thrift.TProcessorFunction (wrong type for Process method) have Process(int32, thrift.TProtocol, thrift.TProtocol) (bool, thrift.TException) want Process(context.Context, int32, thrift.TProtocol, thrift.TProtocol) (bool, thrift.TException)

    vendor/github.com/openzipkin/zipkin-go-opentracing/_thrift/gen-go/scribe/scribe.go:157:27: not enough arguments in call to processor.Process have (int32, thrift.TProtocol, thrift.TProtocol) want (context.Context, int32, thrift.TProtocol, thrift.TProtocol)

  • Favor local communication if possible

    Favor local communication if possible

    Today even if two actors are deployed in the same actor system, gosiris will use the transport defined (if any). This means gosiris will publish a message to Kafka or AMQP for example.

    If two actors are deployed in the same system (i.e. local), they should communicate using a local golang channel (just like if no transport was specified).

Skynet is a framework for distributed services in Go.
Skynet is a framework for distributed services in Go.

##Introduction Skynet is a communication protocol for building massively distributed apps in Go. It is not constrained to Go, so it will lend itself n

Nov 18, 2022
Cross-platform grid-based user interface framework.

Gruid The gruid module provides packages for easily building grid-based applications in Go. The library abstracts rendering and input for different pl

Nov 23, 2022
a dynamic configuration framework used in distributed system
a dynamic configuration framework used in distributed system

go-archaius This is a light weight configuration management framework which helps to manage configurations in distributed system The main objective of

Dec 9, 2022
Go Micro is a standalone framework for distributed systems development

Go Micro Go Micro is a framework for distributed systems development. Overview Go Micro provides the core requirements for distributed systems develop

Dec 31, 2022
a Framework for creating microservices using technologies and design patterns of Erlang/OTP in Golang
a Framework for creating microservices using technologies and design patterns of Erlang/OTP in Golang

Technologies and design patterns of Erlang/OTP have been proven over the years. Now in Golang. Up to x5 times faster than original Erlang/OTP in terms

Dec 28, 2022
Tarmac is a unique framework designed for the next generation of distributed systems
Tarmac is a unique framework designed for the next generation of distributed systems

Framework for building distributed services with Web Assembly

Dec 31, 2022
A Distributed Content Licensing Framework (DCLF) using Hyperledger Fabric permissioned blockchain.

A Distributed Content Licensing Framework (DCLF) using Hyperledger Fabric permissioned blockchain.

Nov 4, 2022
An actor framework for Go

gosiris is an actor framework for Golang. Features Manage a hierarchy of actors (each actor has its own: state, behavior, mailbox, child actors) Deplo

Dec 28, 2022
Thespian is a library supporting use of the actor model in Go code.

Thespian is a library supporting use of the actor model in Go code.

Nov 24, 2021