1

我有一个在 WildFly 上运行的 Java Batch (JSR-352) 应用程序。该应用程序正在公开一个 rest-api 以触发作业执行。我想将一些来自 HTTP REST 请求的值提供给 Reader 类。实现这一点的最佳方法是什么?

作业开始的 REST API:

@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response handleFileReady(MyNotification notification) {
   final Properties jobParams = new Properties();
   jobParams.setProperty("filename", notification.getFileName());

   BatchRuntime.getJobOperator().start("filetransfer", jobParams);
   return Response.status(Response.Status.NO_CONTENT).build();
}

我想从中读取值的读者:

public class MyJobReader extends AbstractItemReader {

    @Override
    public Integer readItem() throws Exception {
       // Get Values here
       ...

另外,目前我通过读取通知对象在属性中设置字符串值,是否有更好的方法来提供整个对象?

4

2 回答 2

1

通过注入 JobContext 我现在可以获得执行 ID:

public class MyJobReader extends AbstractItemReader {

    @Inject
    private JobContext jobContext;

    @Override
    public Integer readItem() throws Exception {

        Properties pros = BatchRuntime.getJobOperator().getParameters(jobContext.getExecutionId());

于 2019-04-15T14:58:39.050 回答
1

You can pass them as query strings in your http request, and your REST resource class then pass them as batch job parameters. In your job xml files, you pass job parameters to your reader as reader's batch properties. Your reader class then inject these batch properties as class fields.

This is how it is done in jberet-rest.

于 2019-04-15T16:27:41.653 回答