GithubHelp home page GithubHelp logo

smilodon's Introduction

smilodon

release:0.3.3 Spring Boot Version:2.3.0.RELEASE Spring Cloud Version:Hoxton.SR8 last-commit

简介

smilodon smilodon中文是剑齿虎,是一套服务注册发现工具包,实现的目的是更好了解微服务的原理,实现spring-cloud-commons部分功能,支持@LoadBalanced注解,可以使用RestTemplate调用服务

smilodon服务器

配置smilodon服务器
  • 先决条件
    • JDK 1.8或更高
    • springboot 2.3或更高
    • springcloud Hoxton.SR8或更高
  • maven 依赖
    <dependency>
        <groupId>cn.lilq.smilodon</groupId>
        <artifactId>smilodon-server-spring-boot-starter</artifactId>
        <version>0.2.4</version>
    </dependency>
构建smilodon服务器
  • 启用smilodon服务器
    @EnableSmilodonServer
    @SpringBootApplication
    public class SmilodonServerApplication {
        public static void main(String[] args) {
            SpringApplication.run(SmilodonServerApplication.class,args);
        }
    }
  • 可选配置
    smilodon.instance.prefer-ip-address=true
    smilodon.instance.hostname=127.0.0.1
    smilodon.server.max-wait-time=60
    smilodon.server.testing-time=20

smilodon客户端

配置smilodon客户端
  • 先决条件
    • JDK 1.8或更高
    • springboot 2.3或更高
    • springcloud Hoxton.SR8或更高
  • maven 依赖
    <dependency>
        <groupId>cn.lilq.smilodon</groupId>
        <artifactId>smilodon-client-spring-boot-starter</artifactId>
        <version>0.2.4</version>
    </dependency>
构建smilodon客户端
  • 启用smilodon服务器
    @EnableSmilodonClient
    @SpringBootApplication
    public class SmilodonClientApplication {
        public static void main(String[] args) {
            SpringApplication.run(SmilodonClientApplication.class,args);
        }
    }
  • 可选配置
    smilodon.instance.prefer-ip-address=true
    smilodon.instance.instance-id=ordersys5001
    smilodon.client.fetch-registry=false
    #smilodon.client.fetch-registry=true
    smilodon.client.service-url=http://localhost:7010
    #smilodon.client.register-with-smilodon=false
    smilodon.client.register-with-smilodon=true
  • 使用discoveryClient进行服务发现
    @Resource
    private DiscoveryClient discoveryClient;
    
    @ResponseBody
    @RequestMapping(value = "/",method = RequestMethod.GET)
    public void getServices(){
        System.out.println(discoveryClient.getServices());
    }
    
    @ResponseBody
    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    public void getInstances(@PathVariable String id){
        System.out.println(discoveryClient.getInstances(id));
    }
  • 使用具有@LoadBalanced注解的RestTemplate调用服务
    @ResponseBody
    @RequestMapping(value = "/hello", method = RequestMethod.GET)
    public Response hello() {
        return new Response(200,"successful","hello world,port:"+serverPort);
    }
    
    @ResponseBody
    @RequestMapping(value = "/sayhello", method = RequestMethod.GET)
    public Response sayHello() {
        Response response = restTemplate.getForObject("http://ORDER-SERVER/hello", Response.class);
        System.out.println(response);
        return response;
    }
    
    @Bean
    @LoadBalanced
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }

演示

不足

  • 动态注入controller
  • 心跳检测
  • 订阅controller 动态注入 (注入异常)

smilodon's People

Contributors

quan930 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.