jBPM 事件处理机制详解
jBPM 是一款强大的业务流程管理(BPM)框架,广泛应用于企业级工作流自动化。它的事件处理机制是整个系统的核心组成部分之一,用于捕获、传递和响应各种流程状态变化及相关活动触发的事件。以下是有关 jBPM 事件处理机制的详细说明:
1. 事件分类
在 jBPM 中,事件主要分为两类:内置事件和自定义事件。
- 内置事件由引擎自动触发,通常对应于生命周期的关键阶段,例如
processStarted
、nodeEntered
和variableChanged
等。 - 自定义事件则允许开发者通过编程方式显式地发布并订阅特定类型的事件。
2. 事件监听器
为了有效地管理和响应不同种类的事件,jBPM 提供了一种灵活的监听器模式。任何类只要实现了接口 org.jbpm.process.instance.event.ProcessEventListener
或者类似的节点级别监听器接口就可以注册成为全局或者局部范围内的观察者对象。当目标事件发生时,相应的回调函数会被调用执行预定义逻辑操作。
示例代码演示如何设置一个简单的 Process Event Listener:
public class MyProcessEventListener implements ProcessEventListener {
@Override
public void beforeNodeTriggered(ProcessNodeTriggerEvent event) {
System.out.println("Before node triggered: " + event.getNodeInstance().getNodeName());
}
@Override
public void afterNodeLeft(ProcessNodeLeftEvent event) {
System.out.println("After leaving node: " + event.getNodeInstance().getNodeName());
}
}
随后,在启动会话之前需将此实例添加至 KieSession 对象中:
KieServices ks = KieServices.Factory.get();
KieContainer kcontainer = ks.newKieClasspathContainer();
KieBaseConfiguration config = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
config.setOption(EventListenerOption.ENABLED);
KieSession ksession = kcontainer.newKieSession();
ksession.addEventListener(new MyProcessEventListener());
3. 事件传播模型
jBPM 支持两种基本形式的事件分发策略——同步与异步。
- 同步步骤意味着一旦某个动作完成后立即通知所有已登记的兴趣方;而后者则是借助队列缓冲区延迟交付消息直到适当时间点再逐一处理它们。
此外还存在跨边界通信需求的情况下可能涉及到序列化传输等问题也需要特别注意解决办法比如采用 JMS broker作为中介层来辅助完成远程服务之间的协作互动关系建立起来之后才能更好地满足分布式环境下的应用场景要求。
4. 日志记录与调试支持
正如先前提到过的那样,“查看应用程序日志(控制台),应该能看到处理器已经执行完毕并且事件监听器也被告知了各类事件的发生情况。” 这句话强调了良好实践的重要性即始终开启必要的跟踪选项以便于后期分析排查潜在错误所在位置。
在jBPM中,文档通常包含了对事件处理机制的详细说明。事件是流程执行过程中的关键部分,其中包括多种类型,比如:
-
开始事件:当流程实例开始时触发,常常用于启动一系列操作或流程定义。
-
结束事件:流程完成时触发,可用于执行清理或通知操作。
-
边界事件:位于流程图上的特定位置,如条件分支或循环之前/之后,可以用来做出决策或改变流程路径。
要深入了解如何在jBPM中使用这些事件,建议查阅官方文档或者jbpm中文用户手册,那里会提供详细的配置示例和API指南,教你如何设置事件监听器以响应不同的流程事件。
jBPM Documentation
The jBPM Team https://www.jbpm.org/community/team.html version 7.25.0.Final
Table of Contents
1. Overview
1.1. What is jBPM?
1.2. Overview
1.3. Core Engine
1.4. Business Central
1.4.1. Process Designer
1.4.2. Data Modeler
1.4.3. Process Management
1.4.4. Task Inbox
1.4.5. Business Activity Monitoring
1.5. Eclipse Developer Tools
2. Getting Started
2.1. Downloads
2.2. Community
2.3. Sources
2.3.1. License
2.3.2. Source code
2.3.3. Building from source
2.4. Getting Involved
2.4.1. Sign up to jboss.org
2.4.2. Sign the Contributor Agreement
2.4.3. Submitting issues via JIRA
2.4.4. Fork GitHub
2.4.5. Writing Tests
2.4.6. Commit with Correct Conventions
2.4.7. Submit Pull Requests
2.5. What to do if I encounter problems or have questions?
3. Business applications
3.1. Overview
3.2. Create your business application
3.2.1. Generate business application
3.2.2. Manually create business application
3.3. Run your business application
3.3.1. Launch application
3.3.2. Launch application in development mode
3.3.3. Import your business assets project into Business Central
3.4. Configure business application
3.4.1. Configuring core components
3.5. Develop your business application
3.5.1. Data model
3.5.2. Business assets development
3.5.3. Work Item Handlers
3.5.4. Event listeners
3.5.5. Custom REST endpoints
3.6. Deploy business application
3.6.1. OpenShift deployment
3.6.2. Docker deployment
3.6.3. Using external data base
3.7. Tutorials
3.7.1. My First Business Application
3.7.2. Business Application with Business Assets
3.7.3. Business Application with custom work item handlers and event listeners
3.7.4. Business Application with JPA entity
3.7.5. Business Application with ElasticSearch
3.7.6. Business Application with JMS
3.7.7. Business Application with Dynamic Assets
4. jBPM Installer
4.1. Prerequisites
4.2. Downloading the Installer
4.3. Demo Setup
4.4. 10-Minute Tutorial using Business Central
4.5. 10-Minute Tutorial using Eclipse
4.6. Configuration
4.6.1. Business Central Authentication
4.6.2. Using your own database with the jBPM installer
4.6.3. jBPM database schema scripts (DDL scripts)
4.6.4. jBPM installer script
4.7. Frequently Asked Questions
5. Examples
5.1. Introduction
5.2. Importing Projects through Git
5.3. Human Resources Example
5.3.1. The Kie Project: human-resources
5.3.2. Building the Human Resources Example
5.3.3. Create a new Process Instance
5.4. Examples zip
6. jBPM Version Migration Guide
6.1. Deprecated in jBPM 7
6.2. Changed in jBPM 7
7. Core Engine API
7.1. Overview
7.2. KieBase
7.3. KieSession
7.3.1. ProcessRuntime
7.3.2. Event Listeners
7.3.3. Correlation Keys
7.3.4. Threads
7.4. RuntimeManager
7.4.1. Overview
7.4.2. Strategies
7.4.3. Usage
7.4.4. Configuration
7.5. Services
7.5.1. Deployment Service
7.5.2. Definition Service
7.5.3. Process Service
7.5.4. Runtime Data Service
7.5.5. User Task Service
7.5.6. Quartz-based Timer Service
7.5.7. QueryService
7.5.8. ProcessInstanceMigrationService
7.5.9. Working with deployments
7.6. Configuration
8. Processes
8.1. What is BPMN 2.0
8.2. Process
8.2.1. Creating a process
8.3. Activities
8.3.1. Script task
8.3.2. Service task
8.3.3. User task
8.3.4. Reusable sub-process
8.3.5. Business rule task
8.3.6. Embedded sub-process
8.3.7. Multi-instance sub-process
8.4. Events
8.4.1. Start event
8.4.2. End events
8.4.3. Intermediate events
8.5. Gateways
8.5.1. Diverging gateway
8.5.2. Converging gateway
8.6. Others
8.6.1. Variables
8.6.2. Scripts
8.6.3. Constraints
8.6.4. Timers
8.7. Process Fluent API
8.7.1. Example
8.8. Testing
8.8.1. Unit testing
9. Human Tasks
9.1. Introduction
9.2. Using User Tasks in our Processes
9.2.1. Swimlanes
9.3. Task escalations and notifications
9.3.1. Designing a task escalation
9.3.2. Email notifications
9.3.3. Designing email notifications
9.3.4. Time and Duration definitions
9.4. Data Mappings
9.5. Task Lifecycle
9.6. Task Permissions
9.6.1. Task Permissions Matrix
9.7. Task Service and The jBPM engine
9.8. Task Service API
9.8.1. Task event listener
9.8.2. Data model of task service
9.9. Interacting with the Task Service
9.10. Experimental features
9.10.1. SubTasks
10. Persistence and Transactions
10.1. Process Instance State
10.1.1. Runtime State
10.2. Audit Log
10.2.1. The jBPM Audit data model
10.2.2. Storing Process Events in a Database
10.2.3. Storing Process Events in a JMS queue for further processing
10.2.4. Variables auditing
10.3. Transactions
10.3.1. Container managed transactions
10.4. Configuration
10.4.1. Adding dependencies
10.4.2. Manually configuring the jBPM engine to use persistence
10.4.3. Configuring the jBPM engine to use persistence
10.5. Persisting process variables in a separate database schema in jBPM
11. Business Central (General)
11.1. Installation
11.1.1. War installation
11.1.2. Business Central data
11.1.3. System properties
11.1.4. Trouble shooting
11.2. Quick Start
11.2.1. Importing examples
11.2.2. Add Project
11.2.3. Define Data Model
11.2.4. Define Rule
11.2.5. Build and Deploy
11.3. Configuration
11.3.1. Basic user management
11.3.2. Roles
11.4. Introduction
11.4.1. Log in and log out
11.4.2. Home screen
11.4.3. Business Central overview
11.4.4. Business Central user interface concepts
11.5. Changing the layout
11.5.1. Resizing
11.6. Authoring (General)
11.6.1. Artifact Repository
11.6.2. Asset Editor
11.6.3. Tags Editor
11.6.4. Project Explorer
11.6.5. Project Editor
11.6.6. Validation
11.6.7. Data Modeller
11.6.8. Data Sets
11.6.9. Data Source Management
11.7. Security management
11.7.1. Basic concepts
11.7.2. Installation and setup
11.7.3. Usage
11.7.4. Security Settings Editor
11.7.5. Security Policy Storage
11.8. SSH keystore
11.8.1. Introduction
11.8.2. Using the SSH keystore
11.9. Embedding Business Central in Your Application
11.10. Execution Server Management UI
11.10.1. Server Templates
11.10.2. Container
11.10.3. Remote Server
11.11. Experimental Features Framework
11.11.1. Introduction
11.11.2. Types of Experimental Features
11.11.3. Experimental Features Editor
11.11.4. Enabling the Experimental Features Framework
11.12. Business Central profiles
11.12.1. Introduction
11.12.2. Selecting a profile
12. Business Central integration
12.1. Knowledge Store REST API for Business Central spaces and projects
12.1.1. Sending requests with the Knowledge Store REST API using a REST client or curl utility
12.1.2. Supported Knowledge Store REST API endpoints
12.2. Embedded jBPM controller calls
12.3. Keycloak SSO integration
12.3.1. Scenario
12.3.2. Install and set up a Keycloak server
12.3.3. Create and set up the demo realm
12.3.4. Install and set up Business Central
12.3.5. Securing Business Central remote services via Keycloak
12.3.6. Securing Business Central's file system services via Keycloak
12.3.7. Execution server
12.3.8. Consuming remote services
12.3.9. Keycloak and the Business Central's security administration area
13. Business Central High Availability
13.1. VFS clustering
13.2. jBPM clustering
14. Designer
14.1. Designer UI Explained
14.2. Getting started with Modelling
14.3. Designer Toolbar
14.4. Designer keyboard shortcuts overview
14.5. Designer Customization
14.5.1. System Properties
14.5.2. Development System Properties
15. Runtime Management
15.1. Deployments
15.1.1. Deployment descriptors
15.2. Process Deployments
16. Process Management
16.1. Management Screens Overview
16.1.1. Table preferences
16.1.2. Filter dock
16.1.3. Advanced filter dock
16.1.4. Saved Filter dock
16.1.5. The list table area
16.2. Process Management
16.2.1. Process Definitions Management
16.2.2. Process Instances Management
16.3. Tasks Management
16.3.1. Tasks visible to the current user
16.3.2. Task Inbox
16.3.3. Displaying Task variables in Task Inbox and Manage Tasks
16.4. Jobs Management
16.4.1. Bulk actions
16.5. Execution Errors Management
16.5.1. Specific actions for Execution Errors.
17. Business Activity Monitoring
17.1. Overview
17.2. Business Dashboards
17.3. Process & Task Reports
17.3.1. Process Reports
17.3.2. Task Reports
18. KIE Execution Server
18.1. Overview
18.1.1. Glossary
18.2. Installing the KIE Server
18.2.1. Bootstrap switches
18.2.2. Installation details for different containers
18.3. Kie Server setup
18.3.1. Managed Kie Server
18.3.2. Unmanaged KIE Execution Server
18.4. Creating a Kie Container
18.5. Managing Containers
18.5.1. Starting a Container
18.5.2. Stopping and Deleting a Container
18.5.3. Updating a Container
18.6. KIE Server REST API for KIE containers and business assets
18.6.1. Sending requests with the KIE Server REST API using a REST client or curl utility
18.6.2. Sending requests with the KIE Server REST API using the Swagger interface
18.6.3. Supported KIE Server REST API endpoints
18.7. KIE Server Java client API for KIE containers and business assets
18.7.1. Sending requests with the KIE Server Java client API
18.7.2. Supported KIE Server Java clients
18.7.3. Example requests with the KIE Server Java client API
18.8. KIE Server and KIE container commands in jBPM
18.8.1. Sample KIE Server and KIE container commands
18.9. Runtime commands in jBPM
18.9.1. Sample runtime commands in jBPM
18.10. jBPM controller REST API for KIE Server templates and instances
18.10.1. Sending requests with the jBPM controller REST API using a REST client or curl utility
18.10.2. Sending requests with the jBPM controller REST API using the Swagger interface
18.10.3. Supported jBPM controller REST API endpoints
18.11. jBPM controller Java client API for KIE Server templates and instances
18.11.1. Sending requests with the jBPM controller Java client API
18.11.2. Supported jBPM controller Java clients
18.11.3. Example requests with the jBPM controller Java client API
18.12. Securing password using key store
18.12.1. Simple usecase
18.12.2. Implementation and business logic
18.12.3. System requirements
18.12.4. Initialization of a key store
18.12.5. System parameters for loading key store
18.12.6. Example
18.13. Prometheus metrics monitoring in jBPM
18.13.1. Configuring Prometheus metrics monitoring for KIE Server
19. jBPM Eclipse Plugin
19.1. jBPM Eclipse Plugin
19.1.1. Installation
19.1.2. jBPM Project Wizard
19.1.3. New BPMN2 Process Wizard
19.1.4. jBPM Runtime
19.1.5. jBPM Maven Project Wizard
19.1.6. Drools Eclipse plugin
19.2. Debugging
19.2.1. The Process Instances View
19.2.2. The Audit View
19.3. Synchronizing with Business Central Repositories
19.3.1. Importing a Business Central repository
19.3.2. Committing changes to Business Central
19.3.3. Updating from Business Central
19.3.4. Working on individual projects
20. Eclipse BPMN 2.0 Modeler
20.1. Overview
20.2. Installation
20.3. Documentation
21. Integration
21.1. Maven
21.1.1. Maven artifacts as deployment units
21.1.2. Use Maven for dependency management
21.2. CDI
21.2.1. Overview
21.2.2. RuntimeManager as CDI bean
21.3. Spring
21.3.1. Direct use of Runtime Manager API
21.3.2. jBPM services with Spring
21.4. Ejb
21.4.1. Ejb services implementation
21.4.2. Local interface
21.4.3. Remote interface
21.5. OSGi
22. Domain Specific Processes
22.1. Introduction
22.2. Overview
22.2.1. Work Item Definitions
22.2.2. Work Item Handlers
22.3. Example: Notifications
22.3.1. The Notification Work Item Definition
22.3.2. The NotificationWorkItemHandler
22.4. Service Repository
22.4.1. Public jBPM service repository
22.4.2. Building and extending the jBPM Service Repository
22.4.3. Using repository workitems in your processes
22.4.4. Setting up your own service repository
22.4.5. Workitem Configuration (wid) from Handler Annotations
22.4.6. Programatically interacting with the service repository
22.4.7. Defining extended service configuration with JSON
23. Exception Management
23.1. Overview
23.2. Introduction
23.3. Technical Exceptions
23.3.1. Introduction
23.3.2. Handling exceptions in WorkItemHandler instances
23.3.3. Examples
23.4. Business Exceptions
23.4.1. Business Exceptions elements in BPMN2
23.4.2. Designing a workflow with Business Exceptions
24. Flexible Processes
25. Concurrency and asynchronous execution
25.1. Concurrency
25.1.1. Engine execution
25.1.2. Multiple KIE sessions and persistence
25.2. Asynchronous execution
25.2.1. Asynchronous handlers
25.2.2. jbpm executor
26. Release Notes
26.1. jBPM 7.25
26.1.1. New and Noteworthy in jBPM 7.25.0
26.2. jBPM 7.24
26.2.1. New and Noteworthy in jBPM 7.24.0
26.3. jBPM 7.23
26.3.1. New and Noteworthy in Business Central 7.23.0
26.4. jBPM 7.22
26.4.1. New and Noteworthy in jBPM 7.22.0
26.5. jBPM 7.21
26.5.1. New and Noteworthy in jBPM 7.21.0
26.6. jBPM 7.20
26.6.1. New and Noteworthy in jBPM 7.20.0
26.7. jBPM 7.19
26.7.1. New and Noteworthy in jBPM 7.19.0
26.8. jBPM 7.18
26.8.1. New and Noteworthy in jBPM 7.18.0
26.8.2. New and Noteworthy in Business Central 7.18.0
26.9. jBPM 7.17
26.9.1. New and Noteworthy in jBPM 7.17.0
26.9.2. New and Noteworthy in Business Central 7.17.0
26.10. jBPM 7.16
26.10.1. New and Noteworthy in jBPM 7.16.0
26.10.2. New and Noteworthy in Business Central 7.16.0
26.11. jBPM 7.15
26.11.1. New and Noteworthy in jBPM 7.15.0
26.11.2. New and Noteworthy in KIE Workbench 7.15.0
26.12. jBPM 7.14
26.12.1. New and Noteworthy in jBPM 7.14.0
26.12.2. New and Noteworthy in KIE Workbench 7.14.0
26.13. jBPM 7.13
26.13.1. New and Noteworthy in jBPM 7.13.0
26.13.2. New and Noteworthy in KIE Workbench 7.13.0
26.14. jBPM 7.12
26.14.1. New and Noteworthy in jBPM 7.12.0
26.15. jBPM 7.11
26.15.1. New and Noteworthy in jBPM 7.11.0
26.15.2. New and Noteworthy in KIE Workbench 7.11.0
26.16. jBPM 7.10
26.16.1. New and Noteworthy in jBPM 7.10.0
26.17. jBPM 7.9
26.17.1. New and Noteworthy in jBPM 7.9.0
26.18. jBPM 7.8
26.18.1. New and Noteworthy in jBPM 7.8.0
26.18.2. New and Noteworthy in KIE Workbench 7.8.0
26.19. jBPM 7.7
26.19.1. New and Noteworthy in jBPM 7.7.0
26.19.2. New and Noteworthy in KIE Workbench 7.7.0
26.20. jBPM 7.6
26.20.1. New and Noteworthy in jBPM 7.6.0
26.20.2. New and Noteworthy in KIE Workbench 7.6.0
26.21. jBPM 7.5
26.21.1. New and Noteworthy in jBPM 7.5.0
26.21.2. New and Noteworthy in KIE Workbench 7.5.0
26.21.3. New jBPM controller client API
26.21.4. Breaking changes in Kie Server 7.5.1 from 7.0
26.22. jBPM 7.4
26.22.1. New and Noteworthy in jBPM 7.4.0
26.22.2. New and Noteworthy in KIE Workbench 7.4.0
26.23. jBPM 7.3
26.23.1. New and Noteworthy in jBPM 7.3.0
26.23.2. New and Noteworthy in KIE Workbench 7.3.0
26.24. jBPM 7.2
26.24.1. New and Noteworthy in jBPM 7.2.0
26.25. jBPM 7.1
26.25.1. New and Noteworthy in jBPM 7.1.0
26.25.2. New and Noteworthy in KIE Workbench 7.1.0
26.26. jBPM 7.0
26.26.1. New and Noteworthy in jBPM 7.0.0
26.26.2. New and Noteworthy in KIE Workbench 7.0.0
26.26.3. Breaking changes in Kie Server 7.0 from 6.x
26.27. jBPM 6.5
26.27.1. New and Noteworthy in jBPM 6.5.0
26.27.2. New and Noteworthy in KIE Workbench 6.5.0
26.28. jBPM 6.4
26.28.1. New and Noteworthy in jBPM 6.4.0
26.28.2. New and Noteworthy in KIE Workbench 6.4.0
26.29. jBPM 6.3
26.29.1. New and Noteworthy in jBPM 6.3.0
26.29.2. New and Noteworthy in KIE Workbench 6.3.0
26.30. jBPM 6.2
26.30.1. New and Noteworthy in jBPM 6.2.0
26.30.2. New and Noteworthy in KIE Workbench 6.2.0
26.31. jBPM 6.1
26.31.1. New and Noteworthy in jBPM 6.1.0
26.31.2. New and Noteworthy in KIE Workbench 6.1.0
26.32. jBPM 6.0
26.32.1. New and Noteworthy in KIE API 6.0.0
26.32.2. New and Noteworthy in jBPM 6.0.0
26.32.3. New and Noteworthy in KIE Workbench 6.0.0
26.32.4. New and Noteworthy in Integration 6.0.0
jBPMLogo
Getting Started
Introduction and getting started with jBPM
- Overview
1.1. What is jBPM?
jBPM is a flexible Business Process Management (BPM) Suite. It is light-weight, fully open-source (distributed under Apache License 2.0) and written in Java. It allows you to model, execute, and monitor business processes and cases throughout their life cycle.
Process
A business process allows you to model your business goals by describing the steps that need to be executed to achieve those goals, and the order of those goals is depicted using a flow chart. This process greatly improves the visibility and agility of your business logic. jBPM focuses on executable business processes, which are business processes that contain enough detail so they can actually be executed on a BPM jBPM engine. Executable business processes bridge the gap between business users and developers as they are higher-level and use domain-specific concepts that are understood by business users but can also be executed directly.
Business processes need to be supported throughout their entire life cycle: authoring, deployment, process management and task lists, and dashboards and reporting.
The core of jBPM is a light-weight, extensible workflow engine written in pure Java that allows you to execute business processes using the latest BPMN 2.0 specification. It can run in any Java environment, embedded in your application or as a service.
On top of the jBPM engine, a lot of features and tools are offered to support business processes throughout their entire life cycle:
Pluggable human task service based on WS-HumanTask for including tasks that need to be performed by human actors.
Pluggable persistence and transactions (based on JPA / JTA).
Case management capabilities added to the jBPM engine to support more adaptive and flexible use cases
Web-based process designer to support the graphical creation and simulation of your business processes (drag and drop).
Web-based data modeler and form modeler to support the creation of data models and task forms
Web-based, customizable dashboards and reporting
All combined in one web-based Business Central application, supporting the complete BPM life cycle:
Modeling and deployment - author your processes, rules, data models, forms and other assets
Execution - execute processes, tasks, rules and events on the core runtime engine
Runtime Management - work on assigned task, manage process instances, etc
Reporting - keep track of the execution using Business Activity Monitoring capabilities
kie wb after login
Eclipse-based developer tools to support the modeling, testing and debugging of processes
Remote API to jBPM engine as a service (REST, JMS, Remote Java API)
Integration with Maven, Spring, OSGi, etc.
BPM creates the bridge between business analysts, developers and end users by offering process management features and tools in a way that both business users and developers like. Domain-specific nodes can be plugged into the palette, making the processes more easily understood by business users.
jBPM supports case management by offering more advanced features to support adaptive and dynamic processes that require flexibility to model complex, real-life situations that cannot easily be described using a rigid process. We bring control back to the end users by allowing them to control which parts of the process should be executed; this allows dynamic deviation from the process.