Using reactive services

Now that we have a handler, we can connect it to our previously created reactive services. Let's first bind them in our handle through the constructor and use it:

@Componentclass CustomerHandler(val customerService: CustomerService) {  fun get(serverRequest: ServerRequest) =      ok().body(customerService.getCustomer(1), Customer::class.java)}

If we try to run this example now, we will get a compilation error and this is because our service method was defined as:

fun getCustomer(id: Int): Mono<Customer?>

Since Customer is nullable, we cannot bind to Customer::class.java, so let's modify our service interface:

package com.microservices.chapter4import reactor.core.publisher.Fluximport reactor.core.publisher.Monointerface  ...

Get Hands-On Microservices with Kotlin now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.