{"id":13806158,"url":"https://github.com/appform-io/dropwizard-service-discovery","last_synced_at":"2025-05-05T18:47:19.477Z","repository":{"id":37711633,"uuid":"53789166","full_name":"appform-io/dropwizard-service-discovery","owner":"appform-io","description":"Zookeeper service discovery bundle and client for dropwizard.","archived":false,"fork":false,"pushed_at":"2024-04-25T13:17:22.000Z","size":1031,"stargazers_count":18,"open_issues_count":10,"forks_count":30,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-25T11:05:29.611Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"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/appform-io.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":"2016-03-13T14:26:14.000Z","updated_at":"2025-04-03T07:15:37.000Z","dependencies_parsed_at":"2023-02-12T21:00:29.833Z","dependency_job_id":"1759285a-cc03-470f-ba54-59e56bafda5e","html_url":"https://github.com/appform-io/dropwizard-service-discovery","commit_stats":null,"previous_names":["santanusinha/dropwizard-service-discovery"],"tags_count":30,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/appform-io%2Fdropwizard-service-discovery","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/appform-io%2Fdropwizard-service-discovery/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/appform-io%2Fdropwizard-service-discovery/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/appform-io%2Fdropwizard-service-discovery/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/appform-io","download_url":"https://codeload.github.com/appform-io/dropwizard-service-discovery/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252555990,"owners_count":21767271,"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":[],"created_at":"2024-08-04T01:01:08.389Z","updated_at":"2025-05-05T18:47:19.458Z","avatar_url":"https://github.com/appform-io.png","language":"Java","funding_links":[],"categories":["Open Source"],"sub_categories":["Data Stores"],"readme":"# Dropwizard Service Discovery [![Build](https://github.com/appform-io/dropwizard-service-discovery/actions/workflows/merge-update.yml/badge.svg)](https://github.com/appform-io/dropwizard-service-discovery/actions/workflows/merge-update.yml)\nProvides service discovery to dropwizard services. It uses [Ranger](https://github.com/flipkart-incubator/ranger) for service discovery.\n\n## Dependency for bundle\n\u003cdependency\u003e\n    \u003cgroupId\u003eio.appform.dropwizard.discovery\u003c/groupId\u003e\n    \u003cartifactId\u003edropwizard-service-discovery-bundle\u003c/artifactId\u003e\n    \u003cversion\u003e2.1.10-2\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\n## Dependency for ZK client\n```\n \u003cdependency\u003e\n        \u003cgroupId\u003eio.appform.ranger\u003c/groupId\u003e\n        \u003cartifactId\u003eranger-zk-client\u003c/artifactId\u003e\n        \u003cversion\u003e1.0-RC13\u003c/version\u003e\n  \u003c/dependency\u003e\n```\n\n## Dependency for Http client\n```\n \u003cdependency\u003e\n        \u003cgroupId\u003eio.appform.ranger\u003c/groupId\u003e\n        \u003cartifactId\u003eranger-http-client\u003c/artifactId\u003e\n        \u003cversion\u003e1.0-RC13\u003c/version\u003e\n  \u003c/dependency\u003e\n```\n\n## How to use the bundle\n\nYou need to add an instance of type _ServiceDiscoveryConfiguration_ to your Dropwizard configuration file as follows:\n\n```\npublic class AppConfiguration extends Configuration {\n    //Your normal config\n    @NotNull\n    @Valid\n    private ServiceDiscoveryConfiguration discovery = new ServiceDiscoveryConfiguration();\n    \n    //Whatever...\n    \n    public ServiceDiscoveryConfiguration getDiscovery() {\n        return discovery;\n    }\n}\n```\n\nNext, you need to use this configuration in the Application while registering the bundle.\n\n```\npublic class App extends Application\u003cAppConfig\u003e {\n    private ServiceDiscoveryBundle\u003cAppConfig\u003e bundle;\n    @Override\n    public void initialize(Bootstrap\u003cAppConfig\u003e bootstrap) {\n        bundle = new ServiceDiscoveryBundle\u003cAppConfig\u003e() {\n            @Override\n            protected ServiceDiscoveryConfiguration getRangerConfiguration(AppConfig appConfig) {\n                return appConfig.getDiscovery();\n            }\n\n            @Override\n            protected String getServiceName(AppConfig appConfig) {\n                //Read from some config or hardcode your service name\n                //This will be used by clients to lookup instances for the service\n                return \"some-service\";\n            }\n\n            @Override\n            protected int getPort(AppConfig appConfig) {\n                return 8080; //Parse config or hardcode\n            }\n            \n            @Override\n            protected NodeInfoResolver createNodeInfoResolver(){\n                return new DefaultNodeInfoResolver();\n            }\n        };\n        \n        bootstrap.addBundle(bundle);\n    }\n\n    @Override\n    public void run(AppConfig configuration, Environment environment) throws Exception {\n        ....\n        //Register health checks\n        bundle.registerHealthcheck(() -\u003e {\n                    //Check whatever\n                    return HealthcheckStatus.healthy;\n                });\n        ...\n    }\n}\n```\nThat's it .. your service will register to zookeeper when it starts up.\n\nSample config section might look like:\n```\nserver:\n  ...\n  \ndiscovery:\n  namespace: mycompany\n  environment: production\n  zookeeper: \"zk-server1.mycompany.net:2181,zk-server2.mycompany.net:2181\"\n  ...\n  \n...\n```\n\nThe bundle also adds a jersey resource that lets you inspect the available instances.\nUse GET /instances to see all instances that have been registered to your service.\n\n## How to use the client\nThe client needs to be created and started. Once started it should never be stopped before the using service\nitself dies or no queries will ever be made to ZK. Creation of the client is expensive. \n\nImagining ShardInfo is your nodeData.\n\n```\nRangerClient client = SimpleRangerZKClient.\u003cShardInfo\u003ebuilder()\n                .connectionString(\"zk-server1.mycompany.net:2181, zk-server2.mycompany.net:2181\")\n                .namespace(\"mycompany\")\n                .serviceName(\"some-service\")\n                .environment(\"production\")\n                .objectMapper(new ObjectMapper())\n                .deserializer(\n                        data -\u003e {\n                            try {\n                                return environment.getObjectMapper().readValue(data, new TypeReference\u003cServiceNode\u003cShardInfo\u003e\u003e() {\n                                });\n                            } catch (IOException e) {\n                                log.warn(\"Error parsing node data with value {}\", new String(data));\n                            }\n                            return null;\n                        }\n                )\n                .initialCriteria(\n                        shardInfo -\u003e true\n                )\n                .alwaysUseInitialCriteria(true)\n                .build(); \n```\n\nStart the client\n```\nclient.start();\n```\n\nGet a valid node from the client:\n```\nOptional\u003cServiceNode\u003cShardInfo\u003e\u003e node = client.getNode();\n\n//Always check if node is present for better stability\nif(node.isPresent()) {\n    //Use the endpoint details (host, port etc) \n    final String host = node.get().getHost();\n    final int port = node.get().getPort();\n    //Make service calls to the node etc etc\n}\n```\n\nClose the client when not required:\n```\nclient.stop();\n```\n\n*Note*\n- Never save a node. The node query is extremely fast and does not make any remote calls.\n- Repeat the above three times and follow it religiously.\n\n## License\nApache 2\n\n# NOTE\nPackage and group id has changed from `io.dropwizard.discovery` to `io.appform.dropwizard.discovery` from 1.3.12-2.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fappform-io%2Fdropwizard-service-discovery","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fappform-io%2Fdropwizard-service-discovery","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fappform-io%2Fdropwizard-service-discovery/lists"}