Giter Club home page Giter Club logo

zuul-route-jdbc-spring-cloud-starter's Introduction

zuul-route-jdbc-spring-cloud-starter

A Spring Cloud jdbc store for Zuul routes. 将zuul的routes信息存储在关系型数据库中,以方便定义zuul dashboard进行运维管理工作。

Features

Extends the Spring Cloud's DiscoveryClientRouteLocator with capabilities of loading routes out of the configured Cassandra database.

Instead of configuring your routes through zuul.routes like follows:

zuul:
  ignoredServices: '*'
  routes:
    resource:
      path: /api/**
      serviceId: rest-service
    oauth2:
      path: /uaa/**
      serviceId: oauth2-service
      stripPrefix: false

You can store the routes in mysql.

Keep in mind that the other properties except for routes are still relevant.

zuul:
  ignoredServices: '*'
  store:
    jdbc:
      enabled: true

Setup

Make sure the version of String Cloud Starter Zuul your project is using is at compatible with 1.2.4.RELEASE which this project is extending.

Add the Spring Cloud starter to your project:

<dependency>
  <groupId>io.github.yangtao309</groupId>
  <artifactId>zuul-route-jdbc-spring-cloud-starter</artifactId>
  <version>1.0.0-SNAPSHOT</version>
</dependency>

Connect to mysql and create a keyspace:


CREATE TABLE zuul_routes(
    id VARCHAR(50),
    path VARCHAR(500),
    service_id VARCHAR(50),
    url VARCHAR(500),
    strip_prefix tinyint(1),
    retryable tinyint(1),
    sensitive_headers VARCHAR(500),
    PRIMARY KEY(id)
);

Register JdbcOperations bean within your application:

@SpringBootApplication
public static class Application {

  @Bean
  public DataSource dataSource(
      @Value("${spring.datasource.url}") String url,
      @Value("${spring.datasource.username}") String username,
      @Value("${spring.datasource.password}") String password,
      @Value("${spring.datasource.maxActive}") int maxActive) {

    DruidDataSource dataSource = new DruidDataSource();
    dataSource.setUrl(url);
    dataSource.setUsername(username);
    dataSource.setPassword(password);
    dataSource.setMaxActive(maxActive);
    return dataSource;
  }

  @Bean
  public JdbcOperations mysqlJdbcTemplate(@Autowired DataSource dataSource) {
    return new JdbcTemplate(dataSource);
  }
}

Configure the jdbc to be used for loading the Zuul routes:

zuul:
  store:
    jdbc:
      enabled: true

Finally enable the Zuul proxy with @EnableZuulProxyStore - use this annotation as a replacement for standard @EnableZuulProxy:

@EnableZuulProxyStore
@SpringBootApplication
public static class Application {

    ...
}

Properties

zuul.store.jdbc.enabled=true# false by default

License

Apache 2.0

zuul-route-jdbc-spring-cloud-starter's People

Contributors

yangtao309 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

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