VERTX-将参数从一个组合到另一个

发布于 2025-01-22 17:40:46 字数 1061 浏览 2 评论 0原文

我需要一些帮助才能将参数从一个组合传递到另一个参数。如下所示,我想将第二个构图的标签置术传递到最后一个组合中。

public Future<JsonArray> startTest(int jobID, RoutingContext context) {
    LOG.info("-----INside startTest() method-----");
    return jobDao.getJob(jobID, context)
            .compose(job -> productDao.getLabelParameters(job, context))
            .compose(labelParameters -> jobDao.getJobParentChildForPrint(jobID, context, true, labelParameters))
            .compose(parentChildSerials -> {
                    LOG.debug(" Future Returned Job Parent-Child to Print: ");
                    prepareSerialForPrint(parentChildSerials, labelParameters); //Pass Here 
                    return Future.succeededFuture(parentChildSerials);
            })
        .onFailure(error -> {
                LOG.debug("startTest() Failed: ", error);
              })
        .onSuccess(server -> {
                LOG.debug("Finished startTest!!");
                LOG.debug(server.encodePrettily());
              });
}

I need some help to pass parameter from one compose to another. I want to pass the labelParemeters in the second compose into the last compose, as I have shown in the code below.

public Future<JsonArray> startTest(int jobID, RoutingContext context) {
    LOG.info("-----INside startTest() method-----");
    return jobDao.getJob(jobID, context)
            .compose(job -> productDao.getLabelParameters(job, context))
            .compose(labelParameters -> jobDao.getJobParentChildForPrint(jobID, context, true, labelParameters))
            .compose(parentChildSerials -> {
                    LOG.debug(" Future Returned Job Parent-Child to Print: ");
                    prepareSerialForPrint(parentChildSerials, labelParameters); //Pass Here 
                    return Future.succeededFuture(parentChildSerials);
            })
        .onFailure(error -> {
                LOG.debug("startTest() Failed: ", error);
              })
        .onSuccess(server -> {
                LOG.debug("Finished startTest!!");
                LOG.debug(server.encodePrettily());
              });
}

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

并安 2025-01-29 17:40:46

您可以为期货中传递的数据创建一个具有setter/getter的上下文对象。
撰写期货的guareantees串行执行,您可以设置结果,并假设下一个撰写部分中的上下文对象中存在该结果。示例:

public Future<JsonArray> startTest(int jobID, RoutingContext context) {
    MyTestContext myTestCtx = new MyTestConext();

    return jobDao.getJob(jobID, context)
            .compose(job -> {
                myTestCtx.setjob(job);
                return productDao.getLabelParameters(job, context);
            })
            .compose(labelParameters -> {
                myTestCtx.setLabelParameters(labelparameters);
                return jobDao.getJobParentChildForPrint(jobID, context, true, labelParameters);
            })
            .compose(parentChildSerials -> {
                var labelParameters = myTestCtx.getLabelParameters();
                prepareSerialForPrint(parentChildSerials, labelParameters); //Pass Here 
                return Future.succeededFuture(parentChildSerials);
            })
        .onSuccess(server -> LOG.debug("Finished startTest!!"));

}

您还可以为此使用Java记录。

另外,您可以如下嵌套组合零件:

    public Future<JsonArray> startTest(int jobID, RoutingContext context) {
        return jobDao.getJob(jobID, context)
                .compose(job -> productDao.getLabelParameters(job, context))
                .compose(labelParameters -> {
                    return jobDao.getJobParentChildForPrint(jobID, context, true, labelParameters)
                            .compose(parentChildSerials -> {
                                LOG.debug(" Future Returned Job Parent-Child to Print: ");
                                prepareSerialForPrint(parentChildSerials, labelParameters); //Pass Here 
                                return Future.succeededFuture(parentChildSerials);
                            })
                })    
            .onFailure(error -> LOG.debug("startTest() Failed: ", error))
            .onSuccess(server -> LOG.debug(server.encodePrettily()));
    
    }

You can create a context object the has setters/getter for the data that is passed around in the Futures.
Compose guareantees serial execution of your Futures, you can set the results and assume that the result is present in your context object in the next compose section. Example:

public Future<JsonArray> startTest(int jobID, RoutingContext context) {
    MyTestContext myTestCtx = new MyTestConext();

    return jobDao.getJob(jobID, context)
            .compose(job -> {
                myTestCtx.setjob(job);
                return productDao.getLabelParameters(job, context);
            })
            .compose(labelParameters -> {
                myTestCtx.setLabelParameters(labelparameters);
                return jobDao.getJobParentChildForPrint(jobID, context, true, labelParameters);
            })
            .compose(parentChildSerials -> {
                var labelParameters = myTestCtx.getLabelParameters();
                prepareSerialForPrint(parentChildSerials, labelParameters); //Pass Here 
                return Future.succeededFuture(parentChildSerials);
            })
        .onSuccess(server -> LOG.debug("Finished startTest!!"));

}

You can also make use of the java records for this.

Alternatively you can nest the compose parts as follows:

    public Future<JsonArray> startTest(int jobID, RoutingContext context) {
        return jobDao.getJob(jobID, context)
                .compose(job -> productDao.getLabelParameters(job, context))
                .compose(labelParameters -> {
                    return jobDao.getJobParentChildForPrint(jobID, context, true, labelParameters)
                            .compose(parentChildSerials -> {
                                LOG.debug(" Future Returned Job Parent-Child to Print: ");
                                prepareSerialForPrint(parentChildSerials, labelParameters); //Pass Here 
                                return Future.succeededFuture(parentChildSerials);
                            })
                })    
            .onFailure(error -> LOG.debug("startTest() Failed: ", error))
            .onSuccess(server -> LOG.debug(server.encodePrettily()));
    
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文