Flowable 6.6.0 BPMN用户指南-(1)入门 - 1.3.1 创建一个流程引擎

Flowable 6.6.0 用户指南相关文档下载


《Flowable 6.6.0 BPMN用户指南》

Flowable

1 入门

1.1 Flowable是什么?
1.2 Flowable与Activiti
1.3.1 创建一个流程引擎
1.3.2 部署流程定义(第一部分)
1.3.2 部署流程定义(第二部分)
1.3.3 启动流程实例
1.3.4 旁路:事务性
1.3.5 查询并完成任务
1.3.6 编写JavaDelegate
1.3.7 使用历史数据
1.4.1 设置REST应用程序
1.4.2 部署流程定义
1.4.3 启动流程实例
1.4.4 任务列表和完成任务

1.3 创建命令行应用

1.3.1 创建一个流程引擎

In this first tutorial we’re going to build a simple example that shows how to create a Flowable process engine, introduces some core concepts and shows how to work with the API. The screenshots show Eclipse, but any IDE works. We’ll use Maven to fetch the Flowable dependencies and manage the build, but likewise, any alternative also works (Gradle, Ivy, and so on).
在第一个教程中,我们将构建一个简单的示例,演示如何创建一个Flowable流程引擎,介绍一些核心概念,并演示如何使用API。屏幕截图显示的是Eclipse,但是也可以采用其他IDE。我们将使用Maven获取Flowable的依赖项并管理build,同样,也可以采用其他替代方法(Gradle、Ivy等等)。

The example we’ll build is a simple holiday request process:
• the employee asks for a number of holidays
• the manager either approves or rejects the request
• we’ll mimic registering the request in some external system and sending out an email to the employee with the result
First, we create a new Maven project through File → New → Other → Maven Project

在下例中我们将构建一个简单的请假流程:
• 员工要求休假
• 经理批准或拒绝申请
• 我们将模拟在某个外部系统中注册请求,并向员工发送一封包含结果的电子邮件

首先,我们通过File→new→Other→Maven project创建一个新的Maven项目
在这里插入图片描述
In the next screen, we check ‘create a simple project (skip archetype selection)’
在下一个屏幕中,我们选中“创建一个简单的项目(跳过原型选择)”(‘create a simple project (skip archetype selection)’)
在这里插入图片描述

And fill in some ‘Group Id’ and ‘Artifact id’:
并填写’Group Id’和’Artifact Id’:
在这里插入图片描述
We now have an empty Maven project, to which we’ll add two dependencies:

  • The Flowable process engine, which will allow us to create a ProcessEngine object and access the Flowable APIs.
  • An in-memory database, H2 in this case, as the Flowable engine needs a database to store execution and historical data while running process instances. Note that the H2 dependency includes both the database and the driver. If you use another database (for example, PostgresQL, MySQL, and so on), you’ll need to add the specific database driver dependency.
    Add the following to your pom.xml file:

现在我们有一个空的Maven项目,我们将添加两个依赖项:

  • Flowable流程引擎,它允许我们创建ProcessEngine对象并访问Flowable API。
  • 内存数据库,在本例中为H2,因为Flowable引擎在运行流程实例时需要一个数据库来存储执行和历史数据。注意H2依赖项包括数据库和驱动程序。如果使用其他类型的数据库(例如,PostgresQL、MySQL等),则需要添加特定的数据库驱动程序依赖项。
    将以下内容添加到pom.xml文件文件:
<dependencies>
  <dependency>
    <groupId>org.flowable</groupId>
    <artifactId>flowable-engine</artifactId>
    <version>6.6.0</version>
  </dependency>
  <dependency>
    <groupId>com.h2database</groupId>
    <artifactId>h2</artifactId>
    <version>1.3.176</version>
  </dependency>
</dependencies>

If the dependent JARs are not automatically retrieved for some reason, you can right-click the project and select ‘Maven → Update Project’ to force a manual refresh (but this should not be needed, normally). In the project, under ‘Maven Dependencies’, you should now see the flowable-engine and various other (transitive) dependencies.
Create a new Java class and add a regular Java main method:

如果由于某种原因不能自动获取依赖的jar,可以右键单击Project并选择“Maven→update project”强制手动刷新(但通常不需要这样做)。在Project中,在“Maven Dependencies”下,您现在应该可以看到flowable-engine 和各种其他(可传递的)依赖项。
创建一个新的Java类并添加一个常规Java main方法:

package org.flowable;

public class HolidayRequest {

  public static void main(String[] args) {

  }

}

The first thing we need to do is to instantiate a ProcessEngine instance. This is a thread-safe object that you typically have to instantiate only once in an application. A ProcessEngine is created from a ProcessEngineConfiguration instance, which allows you to configure and tweak the settings for the process engine. Often, the ProcessEngineConfiguration is created using a configuration XML file, but (as we do here) you can also create it programmatically. The minimum configuration a ProcessEngineConfiguration needs is a JDBC connection to a database:

我们要做的第一件事是实例化ProcessEngine 实例。这是一个线程安全的对象,通常只需要在应用程序中实例化一次。ProcessEngine是从ProcessEngineConfiguration 实例创建的,它允许您配置和调整流程引擎的设置。通常,ProcessEngineConfiguration是使用XML配置文件创建的,但是(正如我们在这里所做的那样),您也可以通过编程方式创建它。ProcessEngineConfiguration 需要的最小配置是一个到数据库的JDBC连接:

package org.flowable;

import org.flowable.engine.ProcessEngine;
import org.flowable.engine.ProcessEngineConfiguration;
import org.flowable.engine.impl.cfg.StandaloneProcessEngineConfiguration;

public class HolidayRequest {

  public static void main(String[] args) {
    ProcessEngineConfiguration cfg = new StandaloneProcessEngineConfiguration()
      .setJdbcUrl("jdbc:h2:mem:flowable;DB_CLOSE_DELAY=-1")
      .setJdbcUsername("sa")
      .setJdbcPassword("")
      .setJdbcDriver("org.h2.Driver")
      .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE);

    ProcessEngine processEngine = cfg.buildProcessEngine();
  }

}

In the code above, on line 10, a standalone configuration object is created. The ‘standalone’ here refers to the fact that the engine is created and used completely by itself (and not, for example, in a Spring environment, where you’d use the SpringProcessEngineConfiguration class instead). On lines 11 to 14, the JDBC connection parameters to an in-memory H2 database instance are passed. Important: note that such a database does not survive a JVM restart. If you want your data to be persistent, you’ll need to switch to a persistent database and switch the connection parameters accordingly. On line 15 we’re setting a flag to true to make sure that the database schema is created if it doesn’t already exist in the database pointed to by the JDBC parameters. Alternatively, Flowable ships with a set of SQL files that can be used to create the database schema with all the tables manually.
The ProcessEngine object is then created using this configuration (line 17).
You can now run this. The easiest way in Eclipse is to right-click on the class file and select Run As → Java Application:

在上面的代码中,第10行创建了一个独立的配置对象。这里的“独立”指的是引擎是完全独立创建和使用的(而不是在Spring环境中,这样您将使用SpringProcessEngineConfiguration 类)。在第11行到第14行,传递H2内存数据库实例的JDBC连接参数。重要提示:请注意,这样的数据库在JVM重启后不再存在。如果希望数据持久化,则需要切换到持久化数据库并相应地切换连接参数。在第15行,我们将一个标志设置为true,以确保数据库schema如果在JDBC参数所指向的数据库中不存在的情况下被创建。另外,Flowable附带一组SQL文件,可用于手动创建包含所有表的数据库schema。

然后使用此配置创建ProcessEngine对象(第17行)。
你现在可以运行了。Eclipse中最简单的方法是右键单击类文件并选择Run As→Java Application:

在这里插入图片描述
The application runs without problems, however, no useful information is shown in the console except a message stating that the logging has not been configured properly:
该应用程序运行正常,但是控制台中没有显示任何有用的信息,只有一条消息表明日志记录配置不正确:
Flowable uses SLF4J as its logging framework internally. For this example, we’ll use the log4j logger over SLF4j, so add the following dependencies to the pom.xml file:

Flowable在内部使用SLF4J作为日志框架。对于本例,我们将在SLF4j上使用log4j记录器,因此将以下依赖项添加到pom.xml文件文件:
在这里插入图片描述

<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-api</artifactId>
  <version>1.7.30</version>
</dependency>
<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-log4j12</artifactId>
  <version>1.7.30</version>
</dependency>

Log4j needs a properties file for configuration. Add a log4j.properties file to the src/main/resources folder with the following content:

Log4j需要一个属性配置文件。将log4j.properties文件添加到src/main/resources文件夹,其中包含以下内容:

log4j.rootLogger=DEBUG, CA

log4j.appender.CA=org.apache.log4j.ConsoleAppender
log4j.appender.CA.layout=org.apache.log4j.PatternLayout
log4j.appender.CA.layout.ConversionPattern= %d{hh:mm:ss,SSS} [%t] %-5p %c %x - %m%n

Rerun the application. You should now see informative logging about the engine booting up and the database schema being created in the database:
重新运行应用程序。现在您应该可以看到有关引擎启动和正在数据库中创建的数据库schema的信息日志:
在这里插入图片描述

We’ve now got a process engine booted up and ready to go. Time to feed it a process!
我们现在已经启动了一个流程引擎并准备就绪。是时候给它一个流程了!

培训视频推荐

CSDN上提供了Flowable 6.6.0的系列培训视频课程,欢迎有兴趣的朋友前往学习。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
本课程是《Flowable流程入门课程》的后续高级课程。在学习本课程前,应先学习入门课程,以掌握相关基础知识。高级课程着重讲解Flowable工作流的高级概念、复杂理论和实战应用。课程内容包括流程管理思想、技术与标准、工作流的控制模式和资源模式;Flowable数据库表及变量;与Spring、Spring Boot的集成;BPMN 2.0主要类图;Flowable高级服务如JAVA服务任务、脚本任务、Web Service任务、外部工作者任务、多实例任务、补偿处理程序、子流程和调用活动等;Flowable事件侦听器、执行侦听器和任务侦听器;Flowable历史和REST API;Flowable事务、并发性、身份管理及LDAP集成;Flowable高级主题如流程实例迁移、异步执行器的设计与配置、用于高并发的UUID ID生成器、多租户、高级流程引擎配置、执行自定义SQL和实验性流程调试器等;Flowable Eclipse设计器特性及定制;Flowable 事件注册;Flowable相关标准和规范如ISO8601标准和cron等。本课程对Flowable官方文档进行了彻底梳理和融汇贯通,并结合实践,形象生动、系统全面、简单易懂地呈现给大家,让大家从开源软件文档冗长耗时、英文晦涩难懂、概念理解困难、知识点分散等困境中解脱出来,从而能快速地将Flowable具有的高级特性应用到项目的高级需求和复杂实践中去。课程特色:案例和代码驱动、基础概念与经典实战相结合、知识环节融会贯通、关联知识平滑拓展、概念和原理展示形象生动。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

月满闲庭

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值