Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/simonewebdesign/elixir_pubsub
:droplet: Publish/Subscribe utility module
https://github.com/simonewebdesign/elixir_pubsub
elixir pubsub
Last synced: about 1 month ago
JSON representation
:droplet: Publish/Subscribe utility module
- Host: GitHub
- URL: https://github.com/simonewebdesign/elixir_pubsub
- Owner: simonewebdesign
- License: mit
- Created: 2015-06-15T21:21:39.000Z (over 9 years ago)
- Default Branch: main
- Last Pushed: 2023-06-20T15:38:42.000Z (over 1 year ago)
- Last Synced: 2024-11-01T09:35:05.555Z (about 1 month ago)
- Topics: elixir, pubsub
- Language: Elixir
- Homepage: https://hexdocs.pm/pubsub
- Size: 63.5 KB
- Stars: 69
- Watchers: 5
- Forks: 11
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- freaking_awesome_elixir - Elixir - A Publish-Subscribe utility library that implements a pub-sub mechanism to ease the burden of communication on the business logic processes. (Utilities)
- fucking-awesome-elixir - pubsub - A Publish-Subscribe utility library that implements a pub-sub mechanism to ease the burden of communication on the business logic processes. (Utilities)
- awesome-elixir - pubsub - A Publish-Subscribe utility library that implements a pub-sub mechanism to ease the burden of communication on the business logic processes. (Utilities)
README
# Elixir Publish/Subscribe
[![Build Status](https://app.travis-ci.com/simonewebdesign/elixir_pubsub.svg?branch=main)](https://app.travis-ci.com/simonewebdesign/elixir_pubsub) [![Coverage Status](https://coveralls.io/repos/github/simonewebdesign/elixir_pubsub/badge.svg?branch=main)](https://coveralls.io/github/simonewebdesign/elixir_pubsub?branch=main) [![Hex package](https://img.shields.io/hexpm/v/pubsub.svg)](https://hex.pm/packages/pubsub) [![Documentation](https://inch-ci.org/github/simonewebdesign/elixir_pubsub.svg?branch=main)](https://inch-ci.org/github/simonewebdesign/elixir_pubsub) [![Total Downloads](https://img.shields.io/hexpm/dt/pubsub.svg)](https://hex.pm/packages/pubsub)
A Publish/Subscribe utility module that frees your business logic processes from the burden of communication.
## Getting Started
Add `:pubsub` as a dependency to your `mix.exs` file:
``` elixir
defp deps do
[
{:pubsub, "~> 1.0"}
]
end
```Then run `mix deps.get` in your shell to fetch the dependencies.
## Examples
Assuming your client process looks like this:
``` elixir
defmodule Client dodef start(client_name) do
spawn(fn -> loop(client_name) end)
enddef loop(name) do
receive do
message ->
IO.puts "#{name} received `#{message}`"
loop(name)
end
endend
```With `PubSub` you can do this:
``` elixir
iex(1)> {topic1, topic2} = {:erlang, :elixir}
{:erlang, :elixir}iex(2)> {:ok, pid} = PubSub.start_link()
{:ok, #PID<0.99.0>}iex(3)> {pid1, pid2, pid3} =
...(3)> {
...(3)> Client.start("John"),
...(3)> Client.start("Nick"),
...(3)> Client.start("Tim")
...(3)> }
{#PID<0.106.0>, #PID<0.107.0>, #PID<0.108.0>}iex(4)> PubSub.subscribe(pid1, topic1)
:ok
iex(5)> PubSub.subscribe(pid2, topic1)
:ok
iex(6)> PubSub.subscribe(pid3, topic2)
:okiex(7)> PubSub.publish(topic1, "#{topic1} is great!")
"Nick received `erlang is great!`"
"John received `erlang is great!`"
:okiex(8)> PubSub.publish(topic2, "#{topic2} is so cool, dude")
"Tim received `elixir is so cool, dude`"
:ok
```## API Reference
https://hexdocs.pm/pubsub/PubSub.html