当前位置: 首页>>代码示例>>Java>>正文


Java Mono.flatMap方法代码示例

本文整理汇总了Java中reactor.core.publisher.Mono.flatMap方法的典型用法代码示例。如果您正苦于以下问题:Java Mono.flatMap方法的具体用法?Java Mono.flatMap怎么用?Java Mono.flatMap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在reactor.core.publisher.Mono的用法示例。


在下文中一共展示了Mono.flatMap方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: geometryLocation

import reactor.core.publisher.Mono; //导入方法依赖的package包/类
Mono<GeographicCoordinates> geometryLocation(final Mono<GeoLocationResponse> geoLocationResponseMono) {
    return geoLocationResponseMono.flatMap(geoLocationResponse -> {
                if (geoLocationResponse.getStatus() != null) {
                    switch (geoLocationResponse.getStatus()) {
                        case OK_STATUS:
                            return Mono.just(
                                    new GeographicCoordinates(geoLocationResponse.getResults()[0].getGeometry().getLocation().getLat(),
                                            geoLocationResponse.getResults()[0].getGeometry().getLocation().getLng()));
                        case ZERO_RESULTS:
                            return Mono.error(new GeoLocationNotFoundException(ADDRESS_NOT_FOUND));
                        default:
                            return Mono.error(new GetGeoLocationException(ERROR_GETTING_LOCATION));
                    }
                } else {
                    return Mono.error(new GetGeoLocationException(ERROR_LOCATION_WAS_NULL));
                }
            }
    );
}
 
开发者ID:LearningByExample,项目名称:reactive-ms-example,代码行数:20,代码来源:GeoLocationServiceImpl.java

示例2: count

import reactor.core.publisher.Mono; //导入方法依赖的package包/类
@GetMapping("/mate")
public Flux<Mate> count(@RequestParam Integer limit) {
    Flux<Mate> goodGuys = repository.findAll();
    Flux<GitterUser> usersInRoom = gitterClient.getUsersInRoom(props.getRoom(), limit);
    Mono<List<GitterUser>> listOfUsers = usersInRoom.collectList();

    return listOfUsers.flatMap(gitterUsers -> {
        return goodGuys.map(mate -> {
            Optional<GitterUser> first = gitterUsers.stream()
                                                    .filter(u -> u.getUsername().equals(mate.nickname))
                                                    .findFirst();
            return new Mate(mate.nickname, mate.firstName, first.isPresent());
        });
    });
}
 
开发者ID:aliaksei-lithium,项目名称:spring5demo,代码行数:16,代码来源:SampleController.java

示例3: serverResponse

import reactor.core.publisher.Mono; //导入方法依赖的package包/类
Mono<ServerResponse> serverResponse(Mono<LocationResponse> locationResponseMono) {
    return locationResponseMono.flatMap(locationResponse ->
            ServerResponse.ok().body(Mono.just(locationResponse), LocationResponse.class));
}
 
开发者ID:LearningByExample,项目名称:reactive-ms-example,代码行数:5,代码来源:ApiHandler.java

示例4: buildUrl

import reactor.core.publisher.Mono; //导入方法依赖的package包/类
Mono<String> buildUrl(final Mono<String> addressMono) {
    return addressMono.flatMap(address -> {
        if (address.equals("")) {
            return Mono.error(new InvalidParametersException(MISSING_ADDRESS));
        }
        return Mono.just(endPoint.concat(ADDRESS_PARAMETER).concat(address));
    });
}
 
开发者ID:LearningByExample,项目名称:reactive-ms-example,代码行数:9,代码来源:GeoLocationServiceImpl.java

示例5: get

import reactor.core.publisher.Mono; //导入方法依赖的package包/类
Mono<GeoLocationResponse> get(final Mono<String> urlMono) {
    return urlMono.flatMap(url -> webClient
            .get()
            .uri(url)
            .accept(MediaType.APPLICATION_JSON)
            .exchange()
            .flatMap(clientResponse -> clientResponse.bodyToMono(GeoLocationResponse.class)));
}
 
开发者ID:LearningByExample,项目名称:reactive-ms-example,代码行数:9,代码来源:GeoLocationServiceImpl.java

示例6: buildUrl

import reactor.core.publisher.Mono; //导入方法依赖的package包/类
Mono<String> buildUrl(final Mono<GeographicCoordinates> geographicCoordinatesMono) {
    return geographicCoordinatesMono.flatMap(geographicCoordinates -> Mono.just(endPoint
            .concat(BEGIN_PARAMETERS)
            .concat(LATITUDE_PARAMETER).concat(Double.toString(geographicCoordinates.getLatitude()))
            .concat(NEXT_PARAMETER)
            .concat(LONGITUDE_PARAMETER).concat(Double.toString(geographicCoordinates.getLongitude()))
            .concat(NEXT_PARAMETER)
            .concat(DATE_PARAMETER).concat(TODAY_DATE)
            .concat(NEXT_PARAMETER)
            .concat(FORMATTED_PARAMETER).concat(NOT_FORMATTED)
    ));
}
 
开发者ID:LearningByExample,项目名称:reactive-ms-example,代码行数:13,代码来源:SunriseSunsetServiceImpl.java

示例7: get

import reactor.core.publisher.Mono; //导入方法依赖的package包/类
Mono<GeoTimesResponse> get(final Mono<String> monoUrl) {
    return monoUrl.flatMap(url -> webClient
            .get()
            .uri(url)
            .accept(MediaType.APPLICATION_JSON)
            .exchange()
            .flatMap(clientResponse -> clientResponse.bodyToMono(GeoTimesResponse.class)));
}
 
开发者ID:LearningByExample,项目名称:reactive-ms-example,代码行数:9,代码来源:SunriseSunsetServiceImpl.java

示例8: createResult

import reactor.core.publisher.Mono; //导入方法依赖的package包/类
Mono<SunriseSunset> createResult(final Mono<GeoTimesResponse> geoTimesResponseMono) {
    return geoTimesResponseMono.flatMap(geoTimesResponse -> {
        if ((geoTimesResponse.getStatus() != null) && (geoTimesResponse.getStatus().equals(STATUS_OK))) {
            return Mono.just(new SunriseSunset(geoTimesResponse.getResults().getSunrise(),
                    geoTimesResponse.getResults().getSunset()));
        } else {
            return Mono.error(new GetSunriseSunsetException(SUNRISE_RESULT_NOT_OK));
        }
    });
}
 
开发者ID:LearningByExample,项目名称:reactive-ms-example,代码行数:11,代码来源:SunriseSunsetServiceImpl.java

示例9: translate

import reactor.core.publisher.Mono; //导入方法依赖的package包/类
static <T extends Throwable> Mono<ThrowableTranslator> translate(final Mono<T> throwable) {
    return throwable.flatMap(error -> Mono.just(new ThrowableTranslator(error)));
}
 
开发者ID:LearningByExample,项目名称:reactive-ms-example,代码行数:4,代码来源:ThrowableTranslator.java

示例10: toMono

import reactor.core.publisher.Mono; //导入方法依赖的package包/类
private <T> Mono<T> toMono(Mono<ClientResponse> monoResponse, Class<T> monoContentType) {
    return monoResponse
            .flatMap(response -> bodyToPublisher(response,
                            BodyExtractors.toMono(monoContentType),
                            ErrorBodyExtractors.toMono(httpErrorReaders)));
}
 
开发者ID:jbrixhe,项目名称:spring-webflux-client,代码行数:7,代码来源:DefaultResponseBodyProcessor.java


注:本文中的reactor.core.publisher.Mono.flatMap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。