尝试从.map调用春季启动微服务之间的通信失败

发布于 2025-01-25 12:10:58 字数 1797 浏览 2 评论 0原文

我想使用反应性编写REST API并获得以下结果。为此,我有2个微服务。

服务1:接收邮政对象并从其数据库中检索一些数据。然后,某些内容与第二个微服务进行通信。然后将服务2响应作为单声道返回给客户。

服务2:接收从服务1传递的数据,并将其保存到数据库,并使用生成的主键返回对象。

这是我的代码。

@PostMapping("/submitData")
public Mono<Object> submitScore(@RequestBody SomeObject someObject){
    //Some Operations
    return contestGiftInfoRepository.findAllDataById(id)                
    .filter(c -> {
        
        if(condition) {
            return true;
        } else {
            return false;
        }
    }).reduce((item1,item2) -> {
        if(condition) {
            return item1;
        }else {
            return item2;
        }
    })
    .defaultIfEmpty(emptyObj)
    .map(resultObj->{
        //DoSome OPeration
        
        WebClient client = WebClient.create("my service Url 2");
        Mono<Obj> response = client.post().uri("/ExecutionPath")
        .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
        .body(Mono.just(resultObj), ResultObj.class)
        .retrieve()
        .bodyToMono(ResponseObj.class);

        return response;

    });
    
}

现在,当我调用Web服务1时,一切正常。当我单独调用第二个Web服务时。 However, when I call the second web service from the first service it returns a result reactor.core.Exceptions$ErrorCallbackNotImplemented: org.springframework.web.reactive.function.client.WebClientResponseException$InternalServerError: 500 Internal Server Error from POST http:// localhost:8085/路径由:org.springframework.web.reaeactive.functive.function.client.webclientresponseexception $ internalServerError:500内部服务器在http:// localhost post http:// localhost中出现500个内部服务器错误, vactive.function.client.webclientResponseException.Create(webclientresponseexception.java:218)以下网站:

我不了解错误消息中的实际问题。我在这里想念什么?

I want to write a Rest API using reactive and achieve the below result. I've 2 microservices for this.

Service 1: Receives a post Object and retrieves some data from its database. The process something then communicate to the second Micro Service. Then return the Service 2 response as a Mono to the client.

Service 2: Receives the Data passed from Service 1 and save it to database and returns the Object with the generated primary key.

Here is my code look like.

@PostMapping("/submitData")
public Mono<Object> submitScore(@RequestBody SomeObject someObject){
    //Some Operations
    return contestGiftInfoRepository.findAllDataById(id)                
    .filter(c -> {
        
        if(condition) {
            return true;
        } else {
            return false;
        }
    }).reduce((item1,item2) -> {
        if(condition) {
            return item1;
        }else {
            return item2;
        }
    })
    .defaultIfEmpty(emptyObj)
    .map(resultObj->{
        //DoSome OPeration
        
        WebClient client = WebClient.create("my service Url 2");
        Mono<Obj> response = client.post().uri("/ExecutionPath")
        .header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
        .body(Mono.just(resultObj), ResultObj.class)
        .retrieve()
        .bodyToMono(ResponseObj.class);

        return response;

    });
    
}

Now When I call the web service 1 everything works fine. When I call the second web service individually that works as well. However, when I call the second web service from the first service it returns a result reactor.core.Exceptions$ErrorCallbackNotImplemented: org.springframework.web.reactive.function.client.WebClientResponseException$InternalServerError: 500 Internal Server Error from POST http://localhost:8085/path Caused by: org.springframework.web.reactive.function.client.WebClientResponseException$InternalServerError: 500 Internal Server Error from POST http://localhost:8085/path at org.springframework.web.reactive.function.client.WebClientResponseException.create(WebClientResponseException.java:218) ~[spring-webflux-5.3.16.jar:5.3.16] Suppressed: reactor.core.publisher.FluxOnAssembly$OnAssemblyException: Error has been observed at the following site(s):

I don't understand the actual issue from the error message. What I'm missing here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文