{"id":15176428,"url":"https://github.com/mnishiguchi/kantan_cluster","last_synced_at":"2025-07-14T21:43:24.645Z","repository":{"id":57512339,"uuid":"420715439","full_name":"mnishiguchi/kantan_cluster","owner":"mnishiguchi","description":"Form a simple Erlang cluster easily in Elixir","archived":false,"fork":false,"pushed_at":"2023-08-23T01:56:10.000Z","size":65,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-10-30T04:49:39.201Z","etag":null,"topics":["elixir","erlang","nerves-device","nerves-project"],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mnishiguchi.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-10-24T15:01:37.000Z","updated_at":"2024-05-18T06:21:49.000Z","dependencies_parsed_at":"2024-09-27T13:04:12.999Z","dependency_job_id":"11b6963f-9af7-4a63-a803-e29d46703a3d","html_url":"https://github.com/mnishiguchi/kantan_cluster","commit_stats":{"total_commits":62,"total_committers":1,"mean_commits":62.0,"dds":0.0,"last_synced_commit":"2083f2d8d9420b6c1cfec69607f6ecadcf3ecdc2"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mnishiguchi%2Fkantan_cluster","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mnishiguchi%2Fkantan_cluster/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mnishiguchi%2Fkantan_cluster/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mnishiguchi%2Fkantan_cluster/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mnishiguchi","download_url":"https://codeload.github.com/mnishiguchi/kantan_cluster/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238319485,"owners_count":19452343,"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":["elixir","erlang","nerves-device","nerves-project"],"created_at":"2024-09-27T13:04:10.410Z","updated_at":"2025-02-11T15:31:36.294Z","avatar_url":"https://github.com/mnishiguchi.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# KantanCluster\n\nかんたんクラスター\n\n[![Hex version](https://img.shields.io/hexpm/v/kantan_cluster.svg \"Hex version\")](https://hex.pm/packages/kantan_cluster)\n[![API docs](https://img.shields.io/hexpm/v/kantan_cluster.svg?label=docs \"API docs\")](https://hexdocs.pm/kantan_cluster)\n[![CI](https://github.com/mnishiguchi/kantan_cluster/actions/workflows/ci.yml/badge.svg)](https://github.com/mnishiguchi/kantan_cluster/actions/workflows/ci.yml)\n\n\u003c!-- MODULEDOC --\u003e\n\nForm a simple Erlang cluster easily in Elixir.\n\nKantanCluster is a thin wrapper around\n[libcluster](https://hexdocs.pm/libcluster) and\n[phoenix_pubsub](https://hexdocs.pm/phoenix_pubsub). It allows you to try out\ndistributed Erlang nodes easily.\n\n\u003c!-- MODULEDOC --\u003e\n\n## Getting started\n\nAdd `kantan_cluster` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:kantan_cluster, \"~\u003e 0.5\"}\n  ]\nend\n```\n\n## Demo\n\nOpen an interactive [Elixir shell\n(IEx)](https://elixir-lang.org/getting-started/introduction.html#interactive-mode)\nin a terminal, and start a node with node name and cookie.\n\n```elixir\niex\n\niex\u003e Mix.install([{:kantan_cluster, \"~\u003e 0.5\"}])\niex\u003e KantanCluster.start_node(sname: :node1, cookie: :hello)\n```\n\nOpen another terminal and do the same with a different node name. Make sure\nthat the cookie is the same.\n\n```elixir\niex\n\niex\u003e Mix.install([{:kantan_cluster, \"~\u003e 0.5\"}])\niex\u003e KantanCluster.start_node(sname: :node2, cookie: :hello)\n```\n\nThese two nodes will be connected to each other automatically.\n\n## Configuration\n\nAlternatively, [options] can be loaded from your project's `config/config.exs`.\nFor available clustering strategies, see https://hexdocs.pm/libcluster/readme.html#clustering.\n\n```elixir\nconfig :kantan_cluster,\n  name: :\"node1@127.0.0.1\",\n  cookie: :super_secure_erlang_magic_cookie,\n  topologies: [gossip_example: [\n    strategy: Cluster.Strategy.Gossip,\n    secret: \"super_secure_gossip_secret\"\n  ]]\n```\n\n## Publish-Subscribe\n\nUnder the hood, `kantan_cluster` uses [phoenix_pubsub] for all the heavy-lifting.\n\n```elixir\n# subscribe to hello topic in one node\niex(hoge@my-machine)\u003e KantanCluster.subscribe(\"hello\")\n```\n\n```elixir\n# publish a message to hello topic in another node\niex(piyo@my-machine)\u003e KantanCluster.broadcast(\"hello\", %{motto: \"元氣があればなんでもできる\"})\n```\n\n```elixir\n# check the mailbox in a node that subscribes hello topic\niex(hoge@my-machine)\u003e flush\n```\n\nThe messages can be handled with a `GenServer` like below.\n\n```elixir\n# Somebody in the cluster may publish temperature data on the topic \"hello_nerves:measurements\".\nmessage = {:hello_nerves_measurements, %{temperature_c: 30.1}, node()}\nKantanCluster.broadcast(\"hello_nerves:measurements\", message)\n\n# Anybody within the same cluster can subscribe to the topic and receive messages on the topic.\nKantanCluster.subscribe(\"hello_nerves:measurements\")\n\n# In the subscribing process, you may receive the message using GenServer's handle_info callback.\ndefmodule HelloNervesSubscriber do\n  use GenServer\n\n  # ...\n\n  @impl GenServer\n  def handle_info({:hello_nerves_measurement, measurement, _node}, state) do\n    {:noreply, %{state | last_measurement: measurement}}\n  end\n```\n\n![kantan_cluster_inky_experiment_20220109_175511](https://user-images.githubusercontent.com/7563926/148710739-a11e504f-3398-4732-8531-cdb9292b672e.jpg)\n\n## Acknowledgements\n\nThis project is inspired by the following:\n- [nerves_pack（vintage_net 含む）を使って Nerves 起動時に`Node.connect()`するようにした by nishiuchikazuma](https://qiita.com/nishiuchikazuma/items/f68d2661959197d0765c)\n- [Forming an Erlang cluster of Pi Zeros by underjord](https://youtu.be/ZdtAVlzFf6Q) --- a great hands-on tutorial for connecting multiple [Nerves] devices\n- [Let's Talk by Herman Verschooten](https://til.verschooten.name/til/2023-08-13/lets-talk)\n- [Exploring Elixir Episode 7: Effortless Scaling With Automatic Clusters](https://www.youtube.com/watch?v=zQEgEnjuQsU)\n- [livebook]\n\n\u003c!-- Links --\u003e\n\n[Erlang magic cookie]: https://erlang.org/doc/reference_manual/distributed.html#security\n[livebook]: https://github.com/livebook-dev/livebook\n[options]: https://hexdocs.pm/kantan_cluster/KantanCluster.html#t:option/0\n[Nerves]: https://www.nerves-project.org/\n[phoenix_pubsub]: https://hexdocs.pm/phoenix_pubsub/Phoenix.PubSub.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmnishiguchi%2Fkantan_cluster","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmnishiguchi%2Fkantan_cluster","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmnishiguchi%2Fkantan_cluster/lists"}