Git Product home page Git Product logo

zkutils-discovery's Introduction

Zookeeper搭建服务注册与发现框架

服务发现

  • 基于正常API方式调用
  • 基于Spring Bean方式注入
  • 基于动态流量的均衡loadbalance策略 (TODO)

服务注册

  • 基于正常API方式调用
  • 基于Spring Bean方式注入

用例

Dns动态注册和查询

spring方式配置

    <!-- dnsquery -->
    <bean class="me.zkutils.discovery.consumer.discovery.ServiceQuery" id="dnsQuery">
        <constructor-arg name="basePath" value="/dns"></constructor-arg>
        <constructor-arg name="connectString" value="localhost"></constructor-arg>
        <property name="providerStrategy"><bean class="org.apache.curator.x.discovery.strategies.RoundRobinStrategy"></bean></property>
    </bean>
    <bean class="me.zkutils.discovery.recipes.dns.DnsQuery" lazy-init="true">
        <constructor-arg ref="dnsQuery"/>
    </bean>

    <!-- dnsregistry -->
    <bean class="me.zkutils.discovery.provider.registry.ServiceRegistry" id="dnsRegistry">
        <constructor-arg name="basePath" value="/dns"></constructor-arg>
        <constructor-arg name="connectString" value="localhost"></constructor-arg>
    </bean>
    <bean class="me.zkutils.discovery.recipes.dns.DnsRegistry" lazy-init="true">
        <constructor-arg ref="dnsRegistry"/>
    </bean>

代码方式

    // dnsregistry
    ServiceRegistry serviceRegistry = new ServiceRegistry("localhost", "/dns");
    serviceRegistry.start();
    DnsRegistry dnsRegistry = new DnsRegistry(serviceRegistry);
    dnsRegistry.register("test.com.up", new DnsEnrty("localhost", 8080));
    ...

    // dnsQuery
    ServiceQuery serviceQuery = new ServiceQuery("localhost", "dns");
    serviceQuery.setProviderStrategy(new RoundRobinStrategy<>());
    serviceQuery.start();
    DnsQuery dnsQuery = new DnsQuery(serviceQuery);
    DnsEntry rst = dnsQuery.resolve("test.com.up");
    ...

zkutils-discovery's People

Contributors

paranoidq avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.