{"id":21023219,"url":"https://github.com/simerplaha/akka-typed-stasher","last_synced_at":"2025-10-05T19:02:47.978Z","repository":{"id":92841197,"uuid":"92294161","full_name":"simerplaha/akka-typed-stasher","owner":"simerplaha","description":"Message stashing akka-typed behaviour","archived":false,"fork":false,"pushed_at":"2017-07-31T16:06:24.000Z","size":52,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-20T13:34:36.371Z","etag":null,"topics":["akka-typed","akka-typed-actors"],"latest_commit_sha":null,"homepage":null,"language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/simerplaha.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-05-24T13:17:11.000Z","updated_at":"2020-04-09T02:04:56.000Z","dependencies_parsed_at":null,"dependency_job_id":"9a2ddc2c-3222-486c-8e27-d287f4dc35f4","html_url":"https://github.com/simerplaha/akka-typed-stasher","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simerplaha%2Fakka-typed-stasher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simerplaha%2Fakka-typed-stasher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simerplaha%2Fakka-typed-stasher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simerplaha%2Fakka-typed-stasher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simerplaha","download_url":"https://codeload.github.com/simerplaha/akka-typed-stasher/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243456569,"owners_count":20293905,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["akka-typed","akka-typed-actors"],"created_at":"2024-11-19T11:17:16.484Z","updated_at":"2025-10-05T19:02:47.873Z","avatar_url":"https://github.com/simerplaha.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Message stashing akka-typed behaviour\n\n## Creating a Stash\n```scala\nval stash = Stash[MyCommand]()\n```\n\n## Stash tied to an actor\n```scala\nval processorActor: ActorRef[MyCommand] = ???\nval dedicatedStash = Stash.dedicated(processorActor)\n```\n\n## Stash that spawn the processor actor\n`Stash.plug` is used when the outside actors should not send messages to the processor actor directly, \nbut submit them to the Stash instead which can be processed by the `processor` actor later.\n\nPlug returns a `Behavior[Push[T]]` that accepts `Push` commands only. This restricts outside actors to only \nsend `Push` commands to the `Stash`. \n\nThe processor actor has access to all the Stash commands.\n\n```scala\n //processor actor gets the Stash instance\ndef processorBehavior(stash: ActorRef[DedicatedStashCommand[MyCommand]]) =\n    Actor.immutable[MyCommand] {\n      (ctx, command) =\u003e\n        //Pop messages from the stash when ready\n        stash ! Pop()\n        Actor.same\n    }\n\n//plug returns a Behavior that wil only accept Push Command.\n//Restrict outside actors to only Push commands into the Stash.\nval plugStash: Behavior[Push[MyCommand]] = Stash.plug(processorBehavior)\n```\n\n## StashType\nMessages can be mapped to different `StashType`s in a `Stash`. Default `StashType` is `FIFO`\n\n1. `FIFO` - Messages get delivered on first in, first out basis\n2. `PopLast` - Delivered only when `FIFO` messages is empty. Useful when an actor receive `StopActorCommand`\nby another actor but the processor actor has `FIFO` messages that require processing before stopping the actor.  \n3. `Fixed` - Always kept in the `Stash` until it's `Clear`ed, `Remove`d or the stash limit is reached. \nUseful for subscription based commands when the client wants to receive period updates of the state\nof an Actor. `Iterator` command can be used to send the state to the clients. `Stash.watchAndRemove` can be used \nto automatically remove these subscription commands from the `Stash` if the client dies.\n4. `FixedTap` - Like `Fixed` but delivered initially to the processor as an alert.\n4. `Skip` - Do not get stashed and are delivered to the processor actor instantly.\n\n## Dedicated and plug Stash commands\n```scala\nval messageProcessorActor: ActorRef[String] = ???\nval stash = Stash.dedicated(messageProcessorActor).createActor\n\nstash ! Push(\"message\")\nstash ! Pop()\nstash ! Pop(condition = (command: String) =\u003e true)\n\n//Off/On a stash type\nstash ! Off(StashType.FIFO)\nstash ! On(StashType.FIFO)\n\n//Off all stashes. All messages get delivered to the processor as their arrive and do not get stashed.\nstash ! Off()\n//Continues stashing using the stashMapping provided on start.\nstash ! On()\n\nstash ! ClearStash(StashType.FIFO)\n\nstash ! Clear(condition = (command: String) =\u003e true)\n\nstash ! Iterate(next = (command: String) =\u003e Unit)\n```\n\n## Example Stash config\n```scala\nval stash =\n    Stash[String](\n      fifoOverflowStrategy = OverflowStrategy.DropNewest(limit = 10),\n      fixedOverflowStrategy = OverflowStrategy.DropNewest(limit = 10),\n      popLastOverflowStrategy = OverflowStrategy.DropOldest(limit = 10),\n      //executed when the stash limit is reached. Can be used to reply to the sender of the failure.\n      onCommandDropped = (message: String) =\u003e println(message),\n      //Some messages may have replyTo ActorRef. Stash can watch for these actor and remove the message\n      //if the replyTo actor is terminated\n      watchAndRemove = (message: String) =\u003e None,\n      //maps messages to their target stashes\n      stashMapping = {\n        message: String =\u003e\n          message match {\n            case \"Skip it\" =\u003e StashType.Skip\n            //Other actors send commands to stop the processor actor. This StashType\n            //can be used to make sure that Stop commands are processed only if FIFO\n            //is empty\n            case \"Stop actor\" =\u003e StashType.PopLast\n            //gets removed from the stash only when limit is reached. Useful for subscription based messages.\n            //where clients are subscribed to state changes in an actor.\n            case \"Keep it in stash\" =\u003e StashType.Fixed\n            //Like Fixed, but the processor actor also receives this message initially.\n            case \"Keep it in stash 2\" =\u003e StashType.FixedTap\n            //default\n            case \"First in first out\" =\u003e StashType.FIFO\n          }\n      }\n    )\n```\n\n[Test cases](src/test/scala/stash)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimerplaha%2Fakka-typed-stasher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimerplaha%2Fakka-typed-stasher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimerplaha%2Fakka-typed-stasher/lists"}