发出助焊剂项目时是否可以进行后续的WebClient调用?

时间:2019-02-26 03:32:26

标签: kotlin api-design spring-webflux

我正在使用仅在执行事件搜索API调用时在响应中显示事件场所ID的API。我正在寻找是否有一种方法可以发出Spring WebClient请求,以在发射Flux物品时获取场地信息。

val events =  eventService.fetchEventsByLocation(lat,lon,radius)
            .flatMapIterable { eventResponse ->  EventTransformer.map(eventResponse)}
            .doOnNext { transformedEvent -> this.repository.save(transformedEvent) }


fun fetchEventsByLocation(lat:Double?,lon:Double?,radius:Double?): Mono<EventResponse> {

    val builder = UriComponentsBuilder.fromPath(SEARCH_EVENTS)
            .queryParam("categories", "103")
            .queryParam("location.within", 20.toString() + "mi")
            .queryParam("location.latitude", lat)
            .queryParam("location.longitude", lon)
            .queryParam("token",apiKey)

    return this.webClient.get()
            .uri(builder.toUriString())
            .accept(MediaType.APPLICATION_JSON_UTF8)
            .exchange()
            .flatMap { response -> response.bodyToMono(String::class.java) }
            .map { response -> transform(response) }
}

 fun fetchEventVenue(id:String?): Mono<Venue> {
    val builder = UriComponentsBuilder.fromPath(VENUES + id)
            .queryParam("token",apiKey)

    return this.webClient.get()
            .uri(builder.toUriString())
            .accept(MediaType.APPLICATION_JSON_UTF8)
            .exchange()
            .flatMap { response -> response.bodyToMono(Venue::class.java) }
}

1 个答案:

答案 0 :(得分:1)

doOnNext是中间操作。如果没有终端操作(例如subscribe),则不会使用该流。