{"id":13527156,"url":"https://github.com/apache/incubator-retired-gossip","last_synced_at":"2025-10-08T01:30:20.512Z","repository":{"id":57738714,"uuid":"59881768","full_name":"apache/incubator-retired-gossip","owner":"apache","description":"Mirror of Apache Gossip Incubator","archived":true,"fork":false,"pushed_at":"2018-08-27T14:37:13.000Z","size":1420,"stargazers_count":247,"open_issues_count":4,"forks_count":111,"subscribers_count":40,"default_branch":"master","last_synced_at":"2024-10-02T05:23:36.190Z","etag":null,"topics":["retired"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":false,"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/apache.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2016-05-28T07:00:05.000Z","updated_at":"2024-06-10T13:26:49.000Z","dependencies_parsed_at":"2022-08-24T17:51:10.308Z","dependency_job_id":null,"html_url":"https://github.com/apache/incubator-retired-gossip","commit_stats":null,"previous_names":["apache/incubator-gossip"],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apache%2Fincubator-retired-gossip","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apache%2Fincubator-retired-gossip/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apache%2Fincubator-retired-gossip/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/apache%2Fincubator-retired-gossip/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/apache","download_url":"https://codeload.github.com/apache/incubator-retired-gossip/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235669382,"owners_count":19026815,"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":["retired"],"created_at":"2024-08-01T06:01:42.247Z","updated_at":"2025-10-08T01:30:14.866Z","avatar_url":"https://github.com/apache.png","language":"Java","funding_links":[],"categories":["Java","分布式开发"],"sub_categories":[],"readme":"# Gossip ![Build status](https://travis-ci.org/edwardcapriolo/incubator-gossip.svg?)\n\nGossip 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.\n\nThe original implementation was forked from https://code.google.com/p/java-gossip/. Several bug fixes and changes have already been added.\n\nA set of easily-run examples, illustrating various features of Gossip, are available in the gossip-examples module. The README.md file, in that module described how to run those examples.\n\nBelow, a list of code snippits which show how to incorproate Apache Gossip into your project.  \n\nUsage\n-----\n\nTo gossip you need one or more seed nodes. Seed is just a list of places to initially connect to.\n\n```java\n  GossipSettings settings = new GossipSettings();\n  int seedNodes = 3;\n  List\u003cGossipMember\u003e startupMembers = new ArrayList\u003c\u003e();\n  for (int i = 1; i \u003c seedNodes+1; ++i) {\n    URI uri = new URI(\"udp://\" + \"127.0.0.1\" + \":\" + (50000 + i));\n    startupMembers.add(new RemoteGossipMember(cluster, uri, i + \"\"));\n  }\n```\n\nHere 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.\n\n```java\n  List\u003cGossipService\u003e clients = new ArrayList\u003c\u003e();\n  int clusterMembers = 5;\n  for (int i = 1; i \u003c clusterMembers+1; ++i) {\n    URI uri = new URI(\"udp://\" + \"127.0.0.1\" + \":\" + (50000 + i));\n   GossipService gossipService = new GossipService(cluster, uri, i + \"\",\n             startupMembers, settings, (a,b) -\u003e {});\n  }\n```\n\nLater we can check that the nodes discover each other\n\n```java\n  Thread.sleep(10000);\n  for (int i = 0; i \u003c clusterMembers; ++i) {\n    Assert.assertEquals(4, clients.get(i).getGossipManager().getLiveMembers().size());\n  }\n```\n\nUsage with Settings File\n-----\n\nFor a very simple client setup with a settings file you first need a JSON file such as:\n\n```json\n[{\n  \"cluster\":\"9f1e6ddf-8e1c-4026-8fc6-8585d0132f77\",\n  \"id\":\"447c5bec-f112-492d-968b-f64c8e36dfd7\",\n  \"uri\":\"udp://127.0.0.1:50001\",\n  \"gossip_interval\":1000,\n  \"cleanup_interval\":10000,\n  \"members\":[\n    {\"cluster\": \"9f1e6ddf-8e1c-4026-8fc6-8585d0132f77\",\"uri\":\"udp://127.0.0.1:5000\"}\n  ]\n}]\n```\n\nwhere:\n\n* `cluster` - is the name of the cluster \n* `id` - is a unique id for this node (you can use any string, but above we use a UUID)\n* `uri` - is a URI object containing IP/hostname and port to use on the default adapter on the node's machine\n* `gossip_interval` - how often (in milliseconds) to gossip list of members to other node(s)\n* `cleanup_interval` - when to remove 'dead' nodes (in milliseconds) (deprecated may be coming back)\n* `members` - initial seed nodes\n\nThen starting a local node is as simple as:\n\n```java\nGossipService gossipService = new GossipService(\n  StartupSettings.fromJSONFile( \"node_settings.json\" )\n);\ngossipService.start();\n```\n\nAnd then when all is done, shutdown with:\n\n```java\ngossipService.shutdown();\n```\n\nEvent Listener\n------\n\nThe status can be polled using the getters that return immutable lists.\n\n```java\n   public List\u003cLocalGossipMember\u003e getLiveMembers()\n   public List\u003cLocalGossipMember\u003e getDeadMembers()\n```\n\nThese can be accessed from the `GossipManager` on your `GossipService`, e.g:\n`gossipService.getGossipManager().getLiveMembers();`\n\nUsers can also attach an event listener:\n\n```java\n    GossipService gossipService = new GossipService(cluster, uri, i + \"\", startupMembers,\n    settings, new GossipListener() {\n      @Override\n      public void gossipEvent(GossipMember member, GossipState state) {\n        System.out.println(System.currentTimeMillis() + \" Member \" + j + \" reports \"\n                + member + \" \" + state);\n      }\n  });\n  //The lambda syntax is (a,b) -\u003e { }  //NICE!\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapache%2Fincubator-retired-gossip","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fapache%2Fincubator-retired-gossip","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fapache%2Fincubator-retired-gossip/lists"}