Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of Spring Boot Integrated Workflow engine Camunda

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you the example analysis of Spring Boot integrated workflow engine Camunda, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Process: enter the official website. The main color of the home page reminds me of oranges, with a black Bold menu on a white background at the top, scan it, and click Developers (well, it's intuitive, after all, for development). Hey, found that there is a second-level menu, scan it again, first LEARN it, and then order Build Your First Project. Keep scrolling the mouse, see Quick Start, click Learn more, and open a new tab. Because I had a SpringBoot project, I clicked on SpringBoot directly, and then followed the real Start of the document.

For 1.IDEA to create a SpringBoot project, use Aliyun's Initializr, which is faster than spring.io.

two。 Introducing the dependency of Camunda BPM, I only introduced camunda-bpm-spring-boot-starter-webapp (because I had to use my own MySQL to view the table structure of Camunda), and adjusted the version to 3.4.0.

Then add an empty META-INF/processes.xml file under resources.

(the SpringBoot project of Camunda is introduced, and the table is created automatically at startup)

Add the annotation @ EnableProcessApplication to the 3.Spring Boot program entry.

4. The next step is to design a workflow, you need to download the design software Camunda Modeler, under the bar, do not panic. Then the borrowing workflow is designed with reference to the documentation. Then I design my own workflow according to the needs of the project.

At the beginning of the process, go to "development" first, then output a Boolean value pass,true and pass the "test", while false does not pass the "end of process failure". If you take "test", you will also output a Boolean value pass,true by going "the process ends successfully", otherwise "the process fails".

5. Save the workflow and put it in the resources directory of the SpringBoot project, or you can store it in a new subdirectory under resources to facilitate classified management.

6. The next content is important because it starts to involve coding.

A. first of all, how does the process begin? it's simple.

/ * * Operation process instance * / @ Autowiredprivate RuntimeService runtimeService;ProcessInstance instance = runtimeService.startProcessInstanceByKey (parameter is workflow ID); System.out.println ("instance started successfully, instance ID:" + instance.getProcessInstanceId ())

Remember, this instance ID (not the workflow ID) must be bound to your business, because as soon as the process starts, it will be "developed".

B. the second step is how to set the output parameter pass of the "development" (stepped on a lot of holes)

/ * * Operation task * / @ Autowiredprivate TaskService taskService;Task task = taskService.createTaskQuery () .processInstanceId (the instance that was bound to the business just now) .singleResult (); Map variables = new HashMap (1); variables.put ("pass", true); taskService.complete (task.getId (), variables); System.out.println ("Development task executed successfully, task ID:" + task.getId ())

SingleResult is because I develop only one task here. If you have multiple task in a node of your workflow, use the list () method, and then deal with the task one by one.

Then the "test" is almost the same as "development". Get the task, set the parameters, finish the task, and finish.

C, as for "development" and "testing", what needs to be done in each node, I set up the Listeners of the node to deal with when I design the workflow, there are Execution Listener and Task Listener, and cooperate with Event Type.

These are all the contents of the article "sample Analysis of Spring Boot Integrated Workflow engine Camunda". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report