Skip to content

Simple gossip protocol

License

MIT, Apache-2.0 licenses found

Licenses found

MIT
LICENCE
Apache-2.0
LICENSE
Notifications You must be signed in to change notification settings

systream/simple_gossip

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

41 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

simple_gossip

Simple implementation of gossip protocol. Infect state information around the cluster via gossipping.

Set data

ok = simple_gossip:set({<<"hello world">>, 0}).

Or

ok = simple_gossip:set(fun({Text, Counter}) -> 
                    case Counter rem 10 of 
                      0 -> 
                        no_change; 
                      Rem -> 
                        {change, {Text, Counter+(10-Rem)}} 
                    end
                end).

Retrieve data

{<<"hello world">>, 0} = simple_gossip:get().

Get cluster state.

simple_gossip:status().

Result can be

  • {ok, GossipVsn, LeaderNode, NodesInTheCluster}
  • {error, gossip_vsn_mismatch, LeaderNode, NodesInTheCluster}: Nodes do not agree on cluster state (different GossipVsn). Try again later
  • {error, {timeout, NodesDoNotResponseInTime}, LeaderNode, NodesInTheCluster}: Cannot retrieve information from cluster nodes in time

Subscribe to cluster changes

simple_gossip:subscribe(self()).

It will send a message {data_changed, {<<"hello world">>,0}} to the given process's inbox when the data has been changed.

Unsubscribe from cluster changes

simple_gossip:unsubscribe(self()).

Join node to cluster

simple_gossip:join('test@cluster').

Remove node from cluster

simple_gossip:leave('test@cluster').

Build

$ rebar3 compile

Run tests

$ rebar3 test

About

Simple gossip protocol

Topics

Resources

License

MIT, Apache-2.0 licenses found

Licenses found

MIT
LICENCE
Apache-2.0
LICENSE

Stars

Watchers

Forks

Languages