gossip

A peer to peer cluster discovery service

License

License

GroupId

GroupId

io.teknek
ArtifactId

ArtifactId

gossip
Last Version

Last Version

0.0.3
Release Date

Release Date

Type

Type

jar
Description

Description

gossip
A peer to peer cluster discovery service
Source Code Management

Source Code Management

https://github.com/edwardcapriolo/gossip

Download gossip

How to add to project

<!-- https://jarcasting.com/artifacts/io.teknek/gossip/ -->
<dependency>
    <groupId>io.teknek</groupId>
    <artifactId>gossip</artifactId>
    <version>0.0.3</version>
</dependency>
// https://jarcasting.com/artifacts/io.teknek/gossip/
implementation 'io.teknek:gossip:0.0.3'
// https://jarcasting.com/artifacts/io.teknek/gossip/
implementation ("io.teknek:gossip:0.0.3")
'io.teknek:gossip:jar:0.0.3'
<dependency org="io.teknek" name="gossip" rev="0.0.3">
  <artifact name="gossip" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.teknek', module='gossip', version='0.0.3')
)
libraryDependencies += "io.teknek" % "gossip" % "0.0.3"
[io.teknek/gossip "0.0.3"]

Dependencies

compile (2)

Group / Artifact Type Version
com.fasterxml.jackson : jackson-datatype-json-org jar 1.8.0
log4j : log4j jar 1.2.15

test (2)

Group / Artifact Type Version
junit : junit jar 4.11
io.teknek : tunit jar 0.0.0

Project Modules

There are no modules declared in this project.

This project has been moved to the Apache Software foundation

https://github.com/apache/incubator-gossip [Apache site] (http://gossip.incubator.apache.org)

Gossip Build status

Gossip protocol is a method for a group of nodes to discover and check the liveliness of a cluster. More information can be found at http://en.wikipedia.org/wiki/Gossip_protocol.

The original implementation was forked from https://code.google.com/p/java-gossip/. Several bug fixes and changes have already been added.

Usage

To gossip you need one or more seed nodes. Seed is just a list of places to initially connect to.

  GossipSettings settings = new GossipSettings();
  int seedNodes = 3;
  List<GossipMember> startupMembers = new ArrayList<>();
  for (int i = 1; i < seedNodes+1; ++i) {
    startupMembers.add(new RemoteGossipMember("127.0.0." + i, 2000, i + ""));
  }

Here we start five gossip processes and check that they discover each other. (Normally these are on different hosts but here we give each process a distinct local ip.

  List<GossipService> clients = new ArrayList<>();
  int clusterMembers = 5;
  for (int i = 1; i < clusterMembers+1; ++i) {
    GossipService gossipService = new GossipService("127.0.0." + i, 2000, i + "",
      LogLevel.DEBUG, startupMembers, settings, null);
    clients.add(gossipService);
    gossipService.start();
  }

Later we can check that the nodes discover each other

  Thread.sleep(10000);
  for (int i = 0; i < clusterMembers; ++i) {
    Assert.assertEquals(4, clients.get(i).get_gossipManager().getMemberList().size());
  }

Usage with Settings File

For a very simple client setup with a settings file you first need a JSON file such as:

[{
  "id":"419af818-0114-4c7b-8fdb-952915335ce4",
  "port":50001,
  "gossip_interval":1000,
  "cleanup_interval":10000,
  "members":[
    {"host":"127.0.0.1", "port":50000}
  ]
}]

where:

  • id - is a unique id for this node (you can use any string, but above we use a UUID)
  • port - the port to use on the default adapter on the node's machine
  • gossip_interval - how often (in milliseconds) to gossip list of members to other node(s)
  • cleanup_interval - when to remove 'dead' nodes (in milliseconds)
  • members - initial seed nodes

Then starting a local node is as simple as:

GossipService gossipService = new GossipService(
  StartupSettings.fromJSONFile( "node_settings.json" )
);
gossipService.start();

And then when all is done, shutdown with:

gossipService.shutdown();

Event Listener

The status can be polled using the getters that return immutable lists.

   List<LocalGossipMember> getMemberList()
   public List<LocalGossipMember> getDeadList()

These can be accessed from the GossipManager on your GossipService, e.g: gossipService.get_gossipManager().getMemberList();

Users can also attach an event listener:

  GossipService gossipService = new GossipService("127.0.0." + i, 2000, i + "", LogLevel.DEBUG,
          startupMembers, settings,
          new GossipListener(){
    @Override
    public void gossipEvent(GossipMember member, GossipState state) {
      System.out.println(member+" "+ state);
    }
  });

Maven

You can get this software from maven central.

  <dependency>
       <groupId>io.teknek</groupId>
      <artifactId>gossip</artifactId>
      <version>${pick_the_latest_version}</version>
  </dependency>

Versions

Version
0.0.3
0.0.2
0.0.1
0.0.0