Skip to content

Commit

Permalink
Add current state of demo application
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasgies committed Jul 25, 2019
1 parent 723b284 commit f429c0a
Show file tree
Hide file tree
Showing 28 changed files with 653 additions and 0 deletions.
38 changes: 38 additions & 0 deletions apigateway/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id("org.springframework.boot") version "2.1.6.RELEASE"
id("io.spring.dependency-management") version "1.0.7.RELEASE"
kotlin("jvm") version "1.3.41"
kotlin("plugin.spring") version "1.3.41"
}

group = "de.tobiasgies"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_11

repositories {
mavenCentral()
}

extra["springCloudVersion"] = "Greenwich.SR2"

dependencies {
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("org.springframework.cloud:spring-cloud-starter-gateway")
testImplementation("org.springframework.boot:spring-boot-starter-test")
}

dependencyManagement {
imports {
mavenBom("org.springframework.cloud:spring-cloud-dependencies:${property("springCloudVersion")}")
}
}

tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "1.8"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package de.tobiasgies.apigateway

import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication

@SpringBootApplication
class ApigatewayApplication

fun main(args: Array<String>) {
runApplication<ApigatewayApplication>(*args)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package de.tobiasgies.apigateway

import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import reactor.core.publisher.Mono

@RequestMapping("/local_endpoints")
@RestController
class LocalEndpoints {
@GetMapping("/go_away")
fun goAway() = Mono.just("Go away, Apple has no place in this household!")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package de.tobiasgies.apigateway

import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder
import org.springframework.cloud.gateway.route.builder.routes
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration

@Configuration
class RoutingConfiguration {
@Bean
fun routingDefinition(builder: RouteLocatorBuilder) = builder.routes {
route(id = "bouquet_microservice", order = 1) {
path("/bouquet/*")
uri("http://localhost:8091")
}
route(id = "business_microservice", order = 2) {
path("/business/*")
uri("http://localhost:8092")
}
route(id = "inventory_microservice", order = 3) {
path("/inventory/*")
uri("http://localhost:8093")
}
route(id = "catchall", order = 10) {
alwaysTrue()
uri("forward:/local_endpoints/go_away")
}
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package de.tobiasgies.apigateway

import org.springframework.cloud.gateway.filter.GatewayFilterChain
import org.springframework.cloud.gateway.filter.GlobalFilter
import org.springframework.stereotype.Component
import org.springframework.web.server.ServerWebExchange
import reactor.core.publisher.Mono

/**
* Filters are available in per-route and global versions.
*
* [@Components][Component] that implement [GlobalFilter] are automatically added to the global filter chain. Their
* order of execution can be influenced using [@Ordered][org.springframework.core.Ordered].
*
* BEWARE: Filtering happens after routing. You cannot influence routing decisions in any way using filters. That's what
* [Route Predicates][java.util.function.Predicate] are for.
*/
@Component
class SampleGlobalFilter : GlobalFilter {
override fun filter(exchange: ServerWebExchange?, chain: GatewayFilterChain): Mono<Void> {
// Do something interesting with the request, e.g. manipulate the exchange.
// Afterwards, pass the request on to the next filter in the chain:
return chain.filter(exchange)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package de.tobiasgies.apigateway

import org.springframework.boot.web.embedded.netty.NettyReactiveWebServerFactory
import org.springframework.boot.web.server.WebServerFactoryCustomizer
import org.springframework.stereotype.Component

/**
* Customize the underlying Netty web server.
*
* If the factory itself does not expose a customization option, it is possible to manipulate the
* [reactor.netty.http.server.HttpServer] directly by using [NettyReactiveWebServerFactory.addServerCustomizers].
*/
@Component
class SampleWebServerCustomizer :
WebServerFactoryCustomizer<NettyReactiveWebServerFactory> {
override fun customize(factory: NettyReactiveWebServerFactory) {
// For example: customize TLS settings here
// factory.ssl = Ssl()
// side note: One could use netty-tcnative and its OpenSSL bindings as well.
}
}
2 changes: 2 additions & 0 deletions apigateway/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
server:
port: 8080
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package de.tobiasgies.apigateway

import org.junit.Test
import org.junit.runner.RunWith
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.junit4.SpringRunner

@RunWith(SpringRunner::class)
@SpringBootTest
class ApigatewayApplicationTests {

@Test
fun contextLoads() {
}

}
32 changes: 32 additions & 0 deletions bouquet/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id("org.springframework.boot") version "2.1.6.RELEASE"
id("io.spring.dependency-management") version "1.0.7.RELEASE"
kotlin("jvm") version "1.3.41"
kotlin("plugin.spring") version "1.3.41"
}

group = "de.tobiasgies"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_11

repositories {
mavenCentral()
}

dependencies {
implementation("org.springframework.boot:spring-boot-starter-webflux")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("io.projectreactor:reactor-test")
}

tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "1.8"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package de.tobiasgies.bouquet

import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication

@SpringBootApplication
class BouquetApplication

fun main(args: Array<String>) {
runApplication<BouquetApplication>(*args)
}
13 changes: 13 additions & 0 deletions bouquet/src/main/kotlin/de/tobiasgies/bouquet/BouquetController.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package de.tobiasgies.bouquet

import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import reactor.core.publisher.Mono

@RestController
@RequestMapping("/bouquet")
class BouquetController {
@GetMapping("/hello")
fun hello() = Mono.just("Hello from the bouquet controller!")
}
2 changes: 2 additions & 0 deletions bouquet/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
server:
port: 8091
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package de.tobiasgies.bouquet

import org.junit.Test
import org.junit.runner.RunWith
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.junit4.SpringRunner

@RunWith(SpringRunner::class)
@SpringBootTest
class BouquetApplicationTests {

@Test
fun contextLoads() {
}

}
32 changes: 32 additions & 0 deletions business/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
id("org.springframework.boot") version "2.1.6.RELEASE"
id("io.spring.dependency-management") version "1.0.7.RELEASE"
kotlin("jvm") version "1.3.41"
kotlin("plugin.spring") version "1.3.41"
}

group = "de.tobiasgies"
version = "0.0.1-SNAPSHOT"
java.sourceCompatibility = JavaVersion.VERSION_11

repositories {
mavenCentral()
}

dependencies {
implementation("org.springframework.boot:spring-boot-starter-webflux")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("io.projectreactor:reactor-test")
}

tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "1.8"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package de.tobiasgies.business

import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication

@SpringBootApplication
class BusinessApplication

fun main(args: Array<String>) {
runApplication<BusinessApplication>(*args)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package de.tobiasgies.business

import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
import reactor.core.publisher.Mono

@RestController
@RequestMapping("/business")
class BusinessController {
@GetMapping("/hello")
fun hello() = Mono.just("Hello from the business controller!")
}
2 changes: 2 additions & 0 deletions business/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
server:
port: 8092
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package de.tobiasgies.business

import org.junit.Test
import org.junit.runner.RunWith
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.junit4.SpringRunner

@RunWith(SpringRunner::class)
@SpringBootTest
class BusinessApplicationTests {

@Test
fun contextLoads() {
}

}
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 5 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit f429c0a

Please sign in to comment.