149 lines
7.4 KiB
Kotlin
149 lines
7.4 KiB
Kotlin
package com.kmlabz.birbnetes.apigateway
|
|
|
|
import org.springframework.cloud.gateway.route.RouteLocator
|
|
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder
|
|
import org.springframework.cloud.netflix.hystrix.EnableHystrix
|
|
import org.springframework.context.annotation.Bean
|
|
import org.springframework.context.annotation.Configuration
|
|
|
|
@EnableHystrix
|
|
@Configuration
|
|
class ApiGatewayConfig {
|
|
@Bean
|
|
fun myRoutes(builder: RouteLocatorBuilder): RouteLocator {
|
|
return builder.routes()
|
|
.route { p -> p
|
|
.path("/api/model/v1/model")
|
|
.filters { f -> f
|
|
.hystrix { config ->
|
|
config.name = "model-service-model"
|
|
config.setFallbackUri("forward:/fallback")
|
|
}
|
|
.rewritePath("/api/model/v1/model", "/model")
|
|
}
|
|
.uri("http://model-service")
|
|
}
|
|
.route { p -> p
|
|
.path("/api/model/v1/default")
|
|
.filters { f -> f
|
|
.hystrix { config ->
|
|
config.name = "model-service-default"
|
|
config.setFallbackUri("forward:/fallback")
|
|
}
|
|
.rewritePath("/api/model/v1/default", "/\$default")
|
|
}
|
|
.uri("http://model-service")
|
|
}
|
|
.route { p -> p
|
|
.path("/api/model/v1/model/**")
|
|
.filters { f -> f
|
|
.hystrix { config ->
|
|
config.name = "model-service-model"
|
|
config.setFallbackUri("forward:/fallback")
|
|
}
|
|
.rewritePath("/api/model/v1/model/(?<MODELID>.*)", "/model/\${MODELID}")
|
|
}
|
|
.uri("http://model-service")
|
|
}
|
|
.route { p -> p
|
|
.path("/api/model/v1/model/**/details")
|
|
.filters { f -> f
|
|
.hystrix { config ->
|
|
config.name = "model-service-model"
|
|
config.setFallbackUri("forward:/fallback")
|
|
}
|
|
.rewritePath("/api/model/v1/model/(?<MODELID>.*)/details", "/model/\${MODELID}/details")
|
|
}
|
|
.uri("http://model-service")
|
|
}
|
|
.route { p -> p
|
|
.path("/api/input/v1/sample")
|
|
.filters { f -> f
|
|
.hystrix { config ->
|
|
config.name = "input-service-sample"
|
|
config.setFallbackUri("forward:/fallback")
|
|
}
|
|
.rewritePath("/api/input/v1/sample", "/sample")
|
|
}
|
|
.uri("http://input-service")
|
|
}
|
|
.route { p -> p
|
|
.path("/api/input/v1/sample/**")
|
|
.filters { f -> f
|
|
.hystrix { config ->
|
|
config.name = "input-service-query"
|
|
config.setFallbackUri("forward:/fallback")
|
|
}
|
|
.rewritePath("/api/input/v1/sample/(?<SAMPLEID>.*)", "/sample/\${SAMPLEID}")
|
|
}
|
|
.uri("http://input-service")
|
|
}
|
|
.route { p -> p
|
|
.path("/api/output/v1/result")
|
|
.filters { f -> f
|
|
.hystrix { config ->
|
|
config.name = "output-service-result"
|
|
config.setFallbackUri("forward:/fallback")
|
|
}
|
|
.rewritePath("//api/output/v1/result", "/result")
|
|
}
|
|
.uri("http://output-service-rdb")
|
|
}
|
|
.route { p -> p
|
|
.path("/api/output/v1/result/**")
|
|
.filters { f -> f
|
|
.hystrix { config ->
|
|
config.name = "output-service-query"
|
|
config.setFallbackUri("forward:/fallback")
|
|
}
|
|
.rewritePath("/api/output/v1/result/(?<RESULTID>.*)", "/result/\${RESULTID}")
|
|
}
|
|
.uri("http://output-service-rdb")
|
|
}
|
|
.route { p -> p
|
|
.path("/api/output/v1/result/filter/negative")
|
|
.filters { f -> f
|
|
.hystrix { config ->
|
|
config.name = "output-service-negative"
|
|
config.setFallbackUri("forward:/fallback")
|
|
}
|
|
.rewritePath("/api/output/v1/result/filter/negative", "/result/filter/negative")
|
|
}
|
|
.uri("http://output-service-rdb")
|
|
}
|
|
.route { p -> p
|
|
.path("/api/output/v1/result/filter/positive")
|
|
.filters { f -> f
|
|
.hystrix { config ->
|
|
config.name = "output-service-positive"
|
|
config.setFallbackUri("forward:/fallback")
|
|
}
|
|
.rewritePath("/api/output/v1/result/filter/positive", "/result/filter/positive")
|
|
}
|
|
.uri("http://output-service-rdb")
|
|
}
|
|
.route { p -> p
|
|
.path("/api/output/v1/result/after/**")
|
|
.filters { f -> f
|
|
.hystrix { config ->
|
|
config.name = "output-service-after"
|
|
config.setFallbackUri("forward:/fallback")
|
|
}
|
|
.rewritePath("/api/output/v1/result/after/(?<DATEAFTER>.*)", "/result/after/\${DATEAFTER}")
|
|
}
|
|
.uri("http://output-service-rdb")
|
|
}
|
|
.route { p -> p
|
|
.path("/api/output/v1/result/before/**")
|
|
.filters { f -> f
|
|
.hystrix { config ->
|
|
config.name = "output-service-before"
|
|
config.setFallbackUri("forward:/fallback")
|
|
}
|
|
.rewritePath("/api/output/v1/result/before/(?<DATEBEFORE>.*)", "/result/before/\${DATEBEFORE}")
|
|
}
|
|
.uri("http://output-service-rdb")
|
|
}
|
|
.build()
|
|
}
|
|
} |