项目作者: liemle3893

项目描述 :
A thin, synchronous wrapper on vertx' Zookeeper Backend service discovery. Can be plug into any JVM based project.
高级语言: Java
项目地址: git://github.com/liemle3893/vertx-zookeeper.git
创建时间: 2019-07-07T08:34:30Z
项目社区:https://github.com/liemle3893/vertx-zookeeper

开源协议:Apache License 2.0

下载


= Starter

A thin, synchronous wrapper on vertx’ Zookeeper Backend service discovery. Can be plug into any JVM based project.

  1. repositories {
  2. maven {
  3. url "https://dl.bintray.com/liemle3893/Personal"
  4. }
  5. }
  6. dependencies {
  7. ...
  8. compile 'com.liemlhd.starter:vertx-zookeeper-starter:1.0'
  9. ...
  10. }

Example usage:

  1. public class App {
  2. public static void main(String[] args) throws Exception {
  3. ServiceDiscovery discovery = new ZookeeperServiceDiscovery(Vertx.vertx(), createConfig());
  4. // Service was create with at service type.
  5. /**
  6. * @see {@link com.liemlhd.starter.service_discovery.ServiceType}
  7. * */
  8. ServiceInfo serviceInfo = new ServiceInfo(() -> "test");
  9. ServiceInfo.Address address = new ServiceInfo.Address();
  10. address.setHost("localhost");
  11. address.setPort(12345);
  12. serviceInfo.setName("test");
  13. serviceInfo.setAddress(address);
  14. // Register it
  15. Future<ServiceInfo> promise = discovery.register(serviceInfo);
  16. ServiceInfo s = promise.get();
  17. System.out.println("registered service info: " + s);
  18. // Do something with your service.
  19. // Search for it
  20. SearchCriteria searchCriteria = SearchCriteria.name("test");
  21. Future<List<ServiceInfo>> services = discovery.find( searchCriteria );
  22. System.out.println("services = " + services);
  23. // ...
  24. // Do something with your services.
  25. // Clean up
  26. // Your service will be clean after it shutdown anyway
  27. // but there a may be some delay, so for god's sake, DIY!
  28. discovery.deregister(serviceInfo.getId()); // We do use serviceInfo.getId, so dont forget to saved your registered service info.
  29. }
  30. public static ZkConfig createConfig() {
  31. ZkConfig config = new ZkConfig();
  32. config.setZookeeperHosts("localhost:2181");
  33. return config;
  34. }
  35. }