{"id":18785550,"url":"https://github.com/d-exclaimation/subpub","last_synced_at":"2025-10-08T05:17:57.029Z","repository":{"id":46651062,"uuid":"406718181","full_name":"d-exclaimation/subpub","owner":"d-exclaimation","description":"A lightweight Akka stream PubSub engine for distributing data to multiple consumers.","archived":false,"fork":false,"pushed_at":"2021-11-14T08:08:26.000Z","size":150,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-21T09:55:54.622Z","etag":null,"topics":["akka-actors","akka-streams","pubsub","real-time","scala","topic-modeling"],"latest_commit_sha":null,"homepage":"","language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/d-exclaimation.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-09-15T10:35:26.000Z","updated_at":"2021-11-14T08:08:28.000Z","dependencies_parsed_at":"2022-09-26T22:11:11.795Z","dependency_job_id":null,"html_url":"https://github.com/d-exclaimation/subpub","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/d-exclaimation/subpub","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d-exclaimation%2Fsubpub","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d-exclaimation%2Fsubpub/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d-exclaimation%2Fsubpub/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d-exclaimation%2Fsubpub/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/d-exclaimation","download_url":"https://codeload.github.com/d-exclaimation/subpub/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/d-exclaimation%2Fsubpub/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278891753,"owners_count":26063858,"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","status":"online","status_checked_at":"2025-10-08T02:00:06.501Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-actors","akka-streams","pubsub","real-time","scala","topic-modeling"],"created_at":"2024-11-07T20:48:46.294Z","updated_at":"2025-10-08T05:17:57.006Z","avatar_url":"https://github.com/d-exclaimation.png","language":"Scala","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n\u003cimg src=\"https://github.com/d-exclaimation/subpub/blob/main/icon.png\" width=\"175\" alt=\"logo\" style=\"margin: 1rem\"/\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e \u003ch1\u003eSubPub\u003c/h1\u003e\u003c/p\u003e\n\n\nIn Memory Pub/Sub Engine using Akka Actors and Streams.\n\n## Setup\n\n**Latest Version**: `0.1.9`\n\n```sbt\n\"io.github.d-exclaimation\" %% \"subpub\" % latestVersion\n```\n\n## Feature\n\nSubPub main goals are to:\n\n- Handle creation, distribution, management of both the outgoing stream of data and incoming published data.\n- Differentiate streams based on topic, which can used to push the proper data into the proper streams.\n- Also handles creation in a lazy and concurrent safe way, no need to worry about race conditions.\n- All of the above on lightweight code embedded implementation.\n\n### Consideration\n\nSimilar to `PubSub` from [graphql-subscriptions](https://github.com/apollographql/graphql-subscriptions), SubPub is also\nan in-memory event streaming system that only supports a single server instance. On a production environment, it is\nstrongly recommended to use other implementation that are backed with an external datastore such as Redis or Kafka.\n\nConsider using [Alpakka](https://doc.akka.io/docs/alpakka/current/index.html) instead for this scenario.\n\n## Examples\n\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003eREST + Websocket Realtime API\u003c/b\u003e\u003c/summary\u003e\n\nAn example using this for HTTP + Websocket Realtime API\n\n```scala\nimport io.github.dexclaimation.subpub.SubPub\n\nobject Main extends SprayJsonSupport {\n  // ...\n\n  val pubsub = SubPub()\n\n  val route: Route = {\n    (path(\"send\" / Segment) \u0026 post \u0026 entity(as[JsValue])) { path =\u003e\n      entity(as[JsValue]) {\n        case JsObject(body) =\u003e sendMessage(path, body)\n        case _ =\u003e complete(BadRequest -\u003e JsString(\"Bad message\"))\n      }\n    } ~ path(\"websocket\" / Segment) { path =\u003e\n      handleWebSocketMessages(websocketMessage(path))\n    }\n  }\n\n  // Handle HTTP Post and emit to websocket\n  def sendMessage(path: String, body: Map[String, JsValue]): Route = {\n    try {\n      val content = body(\"content\")\n      val name = body(\"name\")\n      val msg = JsObject(\n        \"content\" -\u003e content,\n        \"name\" -\u003e name,\n        \"createdAt\" -\u003e JsString(Instant.now().toString)\n      )\n      // Push message to subpub\n      pubsub.publish(s\"chat::$path\", msg)\n      complete(OK -\u003e msg)\n    } catch {\n      case NonFatal(_) =\u003e\n        complete(BadRequest -\u003e \"Bad message\")\n    }\n  }\n\n  // Handle Websocket Flow using the topic based Source\n  def websocketMessage(path: String): Flow[Message, TextMessage.Strict, _] = {\n    val source = pubsub\n      .source[JsValue](s\"chat::$path\")\n      .map(_.compactPrint)\n      .map(TextMessage.Strict)\n\n    val sink = Flow[Message]\n      .map(_ =\u003e ()) // On Websocket Message\n      .to(Sink.onComplete(_ =\u003e ())) // on Websocket End\n\n    Flow.fromSinkAndSource(sink, source)\n  }\n\n  // ...\n}\n```\n\n\u003c/details\u003e\n\u003cdetails\u003e\n\u003csummary\u003e\u003cb\u003eRealtime GraphQL API\u003c/b\u003e\u003c/summary\u003e\n\nUsing with a Realtime GraphQL API with Subscription using [Sangria](https://sangria-graphql.github.io/)\nand [OverLayer](https://overlayer.netlify.app).\n\n```scala\nimport io.github.dexclaimation.subpub.SubPub\n\nobject Main {\n  // ...\n\n  val MessageType = ???\n  val (roomArg, stringArg, nameArg) = ???\n\n  val QueryType = ???\n  val MutationType = ObjectType(\n    \"Mutation\",\n    fields[SubPub, Unit](\n      // GraphQL Mutation to send message\n      Field(\"send\", MessageType,\n        arguments = roomArg :: stringArg :: nameArg :: Nil,\n        resolve = { c =\u003e\n          val msg = Message(c arg stringArg, c arg nameArg, Instant.now().toString)\n          // Publish data into subscription\n          c.ctx.publish[Message](c arg roomArg, msg)\n          msg\n        }\n      )\n    )\n  )\n\n  val SubscriptionType = ObjectType(\n    \"Subscription\",\n    field[SubPub, Unit](\n      // GraphQL Subscription to get realtime data stream\n      Field.subs(\"room\", MessageType,\n        arguments = roomArg :: Nil,\n        // Use the Source from SubPub and map it to Action for Sangria\n        resolve = c =\u003e c.ctx.source[Message](c arg roomArg).map(Action(_))\n      )\n    )\n  )\n  val schema = Schema(QueryType, Some(MutationType), Some(SubscriptionType))\n\n  // OverLayer for handling GraphQL over Websocket\n  val gqlTransport = OverTransportLayer(schema, ())\n  val pubsub = SubPub()\n\n  val route: Route =\n    path(\"graphql\" / \"websocket\") {\n      gqlTransport.applyMiddleware(pubsub)\n    }\n}\n```\n\n\u003c/details\u003e\n\n## Feedback\n\nIf you have any feedback, please reach out to me through the issues tab or\nTwitter [@d_exclaimation](https://twitter.com/d_exclaimation)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fd-exclaimation%2Fsubpub","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fd-exclaimation%2Fsubpub","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fd-exclaimation%2Fsubpub/lists"}