From 7b5f535e7bf91ef9c174a75969d81713f8f0f212 Mon Sep 17 00:00:00 2001 From: anthdm Date: Sun, 3 Dec 2023 19:21:47 +0100 Subject: [PATCH] updated readme --- README.md | 77 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 41 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index f13d277..2e571a9 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ [![Go Report Card](https://goreportcard.com/badge/github.com/anthdm/hollywood)](https://goreportcard.com/report/github.com/anthdm/hollywood) ![example workflow](https://github.com/anthdm/hollywood/actions/workflows/build.yml/badge.svg?branch=master) +![Discord Shield](https://discordapp.com/api/guilds/anthonygg/widget.png?style=shield) # Blazingly fast, low latency actors for Golang @@ -85,42 +86,25 @@ func main() { } ``` -## Spawning receivers with configuration +## Spawning receivers (actors) +### With default configuration ```go - e.Spawn(newFoo, "foo", - actor.WithMaxRestarts(4), - actor.WithInboxSize(1024 * 2), - actor.WithTags("bar", "1"), -) + e.Spawn(newFoo, "myactorname") ``` -## Subscribing and publishing to the Eventstream - +### With custom configuration +```go + e.Spawn(newFoo, "myactorname", + actor.WithMaxRestarts(4), + actor.WithInboxSize(1024 * 2), + actor.WithTags("bar", "1"), + ) +) +``` +### As a stateless function +Actors without state can be spawned as a function, because its quick and simple. ```go -e := actor.NewEngine() - -// Subscribe to a various list of events that are being broadcast by -// the engine. -// The eventstream can also be used to publish custom events and notify all of the subscribers.. -eventSub := e.EventStream.Subscribe(func(event any) { - switch evt := event.(type) { - case *actor.DeadLetterEvent: - fmt.Printf("deadletter event to [%s] msg: %s\n", evt.Target, evt.Message) - case *actor.ActivationEvent: - fmt.Println("process is active", evt.PID) - case *actor.TerminationEvent: - fmt.Println("process terminated:", evt.PID) - wg.Done() - default: - fmt.Println("received event", evt) - } -}) - -// Cleanup subscription -defer e.EventStream.Unsubscribe(eventSub) - -// Spawning receiver as a function e.SpawnFunc(func(c *actor.Context) { switch msg := c.Message().(type) { case actor.Started: @@ -128,10 +112,27 @@ e.SpawnFunc(func(c *actor.Context) { _ = msg } }, "foo") - -time.Sleep(time.Second) ``` +## Remote actors +Actors can communicate with eachother over the network with the Remote package. This works the same as local actors but "over the wire". Hollywood supports serialization with Protobuffer or JSON. + +***[Remote actor examples](https://github.com/anthdm/hollywood/tree/master/examples/remote)*** + +## Eventstream +The Eventstream is a powerfull tool that allows you to build flexible and plugable systems without dependencies. + +1. Subscribe any actor to a various list of system events +2. Broadcast your custom events to all subscribers + +You can find more in-depth information on how to use the Eventstream in your application in the Eventstream ***[examples](https://github.com/anthdm/hollywood/tree/master/examples/eventstream)*** + +### List of internal system events +* `ActorStartedEvent` +* `ActorStoppedEvent` + +> TODO add and document more events + ## Customizing the Engine We're using the function option pattern. All function options are in the actor package and start their name with @@ -155,13 +156,12 @@ please see the `actor/deadletter_test.go` file, where a custom deadletter handle Note that you can also provide a custom logger to the engine. See the Logging section for more details. -## Custom middleware +## Middleware You can add custom middleware to your Receivers. This can be usefull for storing metrics, saving and loading data for your Receivers on `actor.Started` and `actor.Stopped`. -For examples on how to implement custom middleware, check out the middleware folder in the * -*[examples](https://github.com/anthdm/hollywood/tree/master/examples/middleware)** +For examples on how to implement custom middleware, check out the middleware folder in the ***[examples](https://github.com/anthdm/hollywood/tree/master/examples/middleware)*** ## Logging @@ -221,6 +221,11 @@ See the log package for more details about the implementation. make test ``` +# Community and discusions +Join our Discord community with over 2000 members for questions and a nice chat. +![Discord Banner 2](https://discordapp.com/api/guilds/anthonygg/widget.png?style=banner2) + + # Used in Production By This project is currently used in production by the following organizations/projects: