This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun view(serverRequest: ServerRequest) = | |
| serverRequest.queryParam("id").map { ownersRepository.findById(it) } | |
| .orElse(Mono.empty<Owner>())// still Java8 Optional here | |
| .and({ (id) -> petRepository.findAllByOwner(id).collectList() }) | |
| // destructuring of Tuple2 possible due to reactor-extensions must | |
| // import reactor.util.function.component1 | |
| // import reactor.util.function.component2 | |
| .flatMap { (owner, pets) -> | |
| val model = mapOf<String, Any>( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun edit(serverRequest: ServerRequest) = serverRequest.body(BodyExtractors.toFormData()) | |
| .flatMap { | |
| val formData = it.toSingleValueMap() | |
| petRepository.save( | |
| Pet(id = formData["id"]!!, | |
| name = formData["name"]!!, | |
| birthDate = formData["birthDate"]!!.toDate(), | |
| owner = formData["ownerId"]!!, | |
| type = formData["type"]!!)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Bean | |
| fun petClinicRouter(ownersHandler: OwnersHandler, | |
| ... | |
| visitHandler: VisitHandler) = | |
| router { | |
| "/owners".nest { | |
| GET("/", ownersHandler::goToOwnersIndex) | |
| "/add".nest { | |
| GET("/", ownersHandler::goToAddPage) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Repository | |
| interface OwnersRepository : ReactiveMongoRepository<Owner, String> | |
| @Repository | |
| interface VisitRepository : ReactiveMongoRepository<Visit, String> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| data class Owner(val firstName: String, val lastName: String) | |
| val loremIpsum = Owner(firstName="Lorem", lastName="Ipsum") | |
| // destructuring | |
| val (firstName, lastName) = loremIpsum |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Bean | |
| public Function<String, String> uppercase() { | |
| return value -> value.toUpperCase(); | |
| } | |
| @Bean | |
| public Function<Flux<String>, Flux<String>> lowercase() { | |
| return flux -> flux.map(value -> value.toLowerCase()); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| interface PersonRepository extends ReactiveCrudRepository<Person, String> { | |
| Flux<Person> findAllByName(String name); | |
| Observable<Person> findByName(String name); | |
| @Tailable | |
| Flux<Person> findBy(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Java functional registration | |
| public RouterFunction<ServerResponse> routingFunction(PersonHandler handler) { | |
| return nest( | |
| path("/person"), nest( | |
| accept(APPLICATION_JSON), | |
| route(GET("/{id}"), handler::getPerson) | |
| .andRoute(method(HttpMethod.GET), handler::listPeople)) | |
| .andRoute(POST("/").and(contentType(APPLICATION_JSON)), handler::createPerson)); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @RestController | |
| class PersonController(val personRepository: PersonRepository) { | |
| @GetMapping("/people") | |
| fun findPeople() = personRepository.findAll() | |
| @GetMapping("/people/{personId}") | |
| fun findPeople(@PathVariable personId:String) = personRepository.findOne(personId) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Run Kafka, Zookeeper, Kafka manager, MongoDB | |
| docker-compose up -d | |
| # ild Producer/Consumer | |
| mvn -f producer/pom.xml clean package | |
| mvn -f consumer/pom.xml clean package | |
| #Run Producer | |
| java -jar producer/target/producer.jar | |
| #Run Consumer |