https://github.com/jeffgbutler/microservice-workshop-kotlin/
https://jeffgbutler.github.io/microservice-workshop-kotlin/
@EnableEurekaServer
to the main Spring Boot classurl
attribute of
@FeignClient
>DiscoveryClient
@Service
class MovieCastService(private val template: RestTemplate, private val discoveryClient: DiscoveryClient) {
fun findCastMembers(movieId: Int): List<CastMember> {
val url = discoveryClient.getInstances("movie-cast-service")
.firstOrNull()?.uri?.toString()
?: throw IllegalStateException("movie-cast-service not available")
val uri = UriComponentsBuilder.fromHttpUrl(url)
.pathSegment("cast")
.pathSegment("search")
.queryParam("movieId", movieId)
.toUriString()
val ent = template.exchange(uri, HttpMethod.GET, null, object : ParameterizedTypeReference<List<CastMember>>() {})
return ent.body ?: emptyList()
}
}
spring.application.name
property. This property
is specified in bootstrap.yml
by convention
name
attribute of a @FeignClient
annotation specifies which service to lookup