简单的基于 Java 的工作流管理器/数据工作流,能够启动 ext。应用程序,调用网络服务等

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11842587/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 06:36:16  来源:igfitidea点击:

Simple java based workflow manager / data workflow with ability to start ext. application, call web services etc

javaworkflowdataflowdata-processing

提问by visionary

First of all, if there is already such a question like mine on the stackoverflow, sorry for that, but I haven't managed to find it. Actually I don't know what tags could I use to search for a solution which I need.

首先,如果stackoverflow上已经有像我这样的问题,抱歉,但我还没有设法找到它。实际上我不知道我可以使用什么标签来搜索我需要的解决方案。

Basically, I need a tool/software which can manage a data(objects) flow using several tools/actions during the whole process. Of course one of the existing BPM/workflow platform tool can probably do that, but they seem to be too complicated for my requirements.

基本上,我需要一个工具/软件,它可以在整个过程中使用多个工具/操作来管理数据(对象)流。当然,现有的 BPM/工作流平台工具之一可能可以做到这一点,但它们似乎对我的要求来说太复杂了。

I have a "static" data model built with JPA/Hibernate. Then I need to change that static model in order to use different processing functions over it. That function could be some java classes, web service or external application (which support batch mode). After that I need to catch the output from these functions and make some visualisations, draw some charts etc. I can assume that all these processing functions have access to the static model and they can change it to that specific one so there is no need to pass input to them. On the other hand the output of them should be caught by the main "workflow manager".

我有一个用 JPA/Hibernate 构建的“静态”数据模型。然后我需要更改该静态模型,以便对其使用不同的处理功能。该函数可以是一些 Java 类、Web 服务或外部应用程序(支持批处理模式)。之后,我需要捕获这些函数的输出并进行一些可视化,绘制一些图表等。我可以假设所有这些处理函数都可以访问静态模型,并且它们可以将其更改为特定的模型,因此无需将输入传递给他们。另一方面,它们的输出应该被主要的“工作流管理器”捕获。

One more thing, the whole process should run automatically without any user interactions (maybe it will change in the future, but look and present for now). Before process starts, administrator should define which "processing function" is used and that's it. And another thing... the best would be if the whole process was triggered when database state was changed, but it is not crucial, I can start it for example by calling a web service.

还有一件事,整个过程应该在没有任何用户交互的情况下自动运行(也许将来会发生变化,但现在看起来和现在)。在流程开始之前,管理员应该定义使用哪个“处理功能”,仅此而已。另一件事......最好是在数据库状态改变时触发整个过程,但这并不重要,我可以通过调用 Web 服务来启动它。

The question is: should I use one of the existing BPM/Workflow tool such as jBPM or Activiti, write a simple "workflow manager" on my own or use an existing tool which is much simpler then jBPM/Activiti (is there any?). Of course I prefer the easiest approach...

问题是:我应该使用现有的 BPM/工作流工具之一,例如 jBPM 或 Activiti,自己编写一个简单的“工作流管理器”还是使用比 jBPM/Activiti 简单得多的现有工具(有没有?) . 当然我更喜欢最简单的方法......

Thanks a lot for any feedback.

非常感谢您的任何反馈。

回答by jainbasil

Apache Camel is an open source integration framework which will help you in this.

Apache Camel 是一个开源集成框架,它将在这方面为您提供帮助。

You can use Apache Camelto build your own simple workflow manager, where each process implements Processor. Your data can passed through processors using camel Exchange. Check out camel examplesfor more information.

您可以使用Apache Camel构建您自己的简单工作流管理器,其中每个进程都实现Processor。您的数据可以使用骆驼交换通过处理器。查看骆驼示例以获取更多信息。

For information on how to write custom processor, please read here.

有关如何编写自定义处理器的信息,请阅读此处

You can add Processors to a Camel RouteBuilder dynamically, schedule it using Quartz Scheduleretc., which will more or less address all your requirements.

您可以将处理器动态添加到 Camel RouteBuilder,使用Quartz Scheduler等对其进行调度,这或多或少会满足您的所有需求。

Here is good introduction to Camel: http://www.kai-waehner.de/blog/2012/05/04/apache-camel-tutorial-introduction/

这是骆驼的好介绍http: //www.kai-waehner.de/blog/2012/05/04/apache-camel-tutorial-introduction/

A simple implementation of Workflow Manager using Camel:

使用 Camel 的工作流管理器的简单实现:

WorkflowManager.java

工作流管理器

import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;

public class WorkflowManager {

    DefaultCamelContext camelContext;

    public WorkflowManager() {
        camelContext = new DefaultCamelContext();
        RouteBuilder routeBuilder = new RouteBuilder() {

            @Override
            public void configure() throws Exception {
                from("timer:schedule?period=1s&daemon=true").process(new ProcessOne()).process(new ProcessTwo());
            }
        };
        try {
            camelContext.addRoutes(routeBuilder);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void start() throws Exception {
        camelContext.start();
    }

    public void stop() throws Exception {
        camelContext.stop();
    }

    public static void main(String[] args) {
        WorkflowManager workflowManager = new WorkflowManager();
        try {
            workflowManager.start();
            while(true) {

            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

ProcessOne.java

ProcessOne.java

import org.apache.camel.Exchange;
import org.apache.camel.Processor;

public class ProcessOne implements Processor {
    @Override
    public void process(Exchange exchange) throws Exception {
        System.out.println("In ProcessOne");
    }
}

ProcessTwo.java

进程二.java

import org.apache.camel.Exchange;
import org.apache.camel.Processor;

public class ProcessTwo implements Processor {
    @Override
    public void process(Exchange exchange) throws Exception {
        System.out.println("In ProcessTwo");
    }
}

I used Camel version 2.9.0 to compile this code. Please note that I've used an infinite loop in main method to keep the main thread alive.

我使用 Camel 2.9.0 版来编译此代码。请注意,我在 main 方法中使用了无限循环来保持主线程处于活动状态。

This code will run a route having ProcessOne and ProcessTwo, with a period of 1 second. You can see the period in from(...) method where I add processors to route builder. Hence, this route will run repeatedly. Also, I am not trying to flow any data. You can use exchange in the process method of each processor to flow data.

此代码将运行具有 ProcessOne 和 ProcessTwo 的路由,周期为 1 秒。您可以在 from(...) 方法中看到我将处理器添加到路由构建器的句点。因此,这条路线将重复运行。另外,我不想传输任何数据。您可以在每个处理器的 process 方法中使用 exchange 来流动数据。

Output will be:

输出将是:

In ProcessOne

In ProcessTwo

In ProcessOne

In ProcessTwo

You can use camel components to make your WorkflowManager robust.

您可以使用骆驼组件来使您的 WorkflowManager 健壮。