Suck the cat with code! This paper is participating in[Cat Essay Campaign].

preface

  • More and more projects are now using workflows for routine tasks. Today we’ll take a look at Activiti’s workflow, and we’ll start with a primer on BPMN painting

Environmental installation

  • The BPMN files for the process are mainly integrated drawing through the Eclipse development tools. ActiBPM is mainly drawn in IDEA, but actiBPM is not maintained after 2014 and is now directly not installed and used in the new IDEA version.
  • In this case you can develop the project with IDEA and draw it through Eclipse, but this situation seems cumbersome. Another integration tool is recommended here to draw BPMN process diagrams
  • Camunda-modeler is a third-party process design tool. Its advantage is that it replaces Eclipse, and we can load it through the External Tools of IDEA.

  • About his configuration is also very simple, click I download EXE.

  • And the rest we can plot.

extension

  • About camunda third-party process drawing software, most will provide community office. They are launched as Java services. Why do we need this approach? This way we can draw the process through Camunda by calling the API. This can be drawn in our own process platform. This plugs the process painter into our own platform system.

Release process

  • First we draw a simple process through Camunda. Above, we started a Camunda platform in the form of Tomcat and published the process we made.

Service task

  • First of all, our card payment is a server operation. Here, we click the Settings bar on the right to set the service mode

  • Finally, the server gets node information by listening, so we need to set the message type (Topic) here.

The gateway

  • Right now our process is pretty simple. Above we set Implementation as External to indicate that the node is co-implemented with External services and specify the message topic. For message monitoring, we will monitor the message in Java mode below. Another important role in the process is the gateway. The gateway here is our judgment node. For example, our credit card payment request has such a requirement
  • Payment approval is required when the payment amount is greater than or equal to 1000 yuan. Less than 1000 yuan can be directly paid.
  • In Camunda there is a graph of x, which is what we call a gateway. Let’s modify the flow chart a little bit

  • Gateways we can just drag and drop in, and they typically have two or more branches. So which branch we’re going to end up on is going to require us to set conditions on each branch. Here we set conditions using Java expressions.

  • Amount is a variable. You can define this variable however you like, but it must be provided at the beginning of the process or an error will be reported

  • We can ask the user to provide the necessary information for the process before the gateway begins

  • Then the reverse process will be carried out according to the amount filled in. Payment approval needs to be approved according to the process information, so I also added the parameter item in filling in the application form. Why do I add this parameter? Let’s say I’m responsible for approving the payment. But I don’t really care about the amount of money, or I just pass some projects mindlessly. At this time, we can realize the automatic approval of this node by means of the automatic decision of the process.
  • Here we introduce the DMN of the process. We create a new DMN file through Camunda. And set the ID of the DMN

  • Then click on the icon in the upper left corner to set the rules

  • Our rules are simple. I approve all item-XYZ items, or nothing.

  • There are many ways we can set this rule. Ours is the only way, which means that each condition is mutually exclusive and black or white. There are other ways we can debug it ourselves

  • Back in our main flow, we select the Implementation mode as DMN, and ref selects the ID of the DMN we set above

Java monitors process information

<dependency>
    <groupId>org.camunda.bpm</groupId>
    <artifactId>camunda-external-task-client</artifactId>
    <version>7.15. 0</version>
</dependency>
<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-simple</artifactId>
    <version>1.61.</version>
</dependency>
<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.31.</version>
</dependency>
Copy the code
  • After we add dependencies here, we start listening for external services in our process’s topic
ExternalTaskClient client = ExternalTaskClient.create()
        .baseUrl("http://localhost:8080/engine-rest")
        .asyncResponseTimeout(10000) // Long polling timeout
        .build();

// Subscribe to the specified external task
client.subscribe("charge-card")
        .lockDuration(1000) // The default lock time is 20 seconds. Change this value to 1 second
        .handler((externalTask, externalTaskService) -> {
            // Write your business logic here

            // Get process variables
            String item = (String) externalTask.getVariable("item");
            Long amount = (Long) externalTask.getVariable("amount");

            LOGGER.info("Charging credit card with an amount of '" + amount + "€for the item" + item + "'...");

            try {
                Desktop.getDesktop().browse(new URI("https://docs.camunda.org/get-started/quick-start/complete"));
            } catch (Exception e) {
                e.printStackTrace();
            }

            // Complete the task
            externalTaskService.complete(externalTask);
        })
        .open();
Copy the code
  • At this point we can look at the log,

Maltcloud integration

  • Workflow is scheduled for phase 2 in the MaltCloud release plan, so I plan to develop workflow operations after maltCloud completes the basic functionality. The first is drawing the process, the basic drawing and publishing of the process has been mentioned above. Let’s take a look at how workflow can be inherited into maltCloud, our enterprise framework.
  • Note that the Springboot and Camunda versions need to match during integration. The official website provides us with the matching scheme of the response version

  • Here’s an explanation
    • The first column [Springboot Starter Version] represents the Springboot starter version of Camunda.
    • The second column [Camunda Platform Version] represents the actual Camunda version
    • The third column [Springboot Version] represents the Springboot version of our system.
  • With maltCloud using the 2.2.2.RELEASE, we can locate the camunda Springboot starter version to be 3.4.x; Then we will go to the Maven repository to check the relevant version

  • Here I chose to use version 3.4.0 initially. It was later discovered that springboot for 2.2.X. lease also supported 7.13.x, and the 7.13.0 version was decided to be used.

  • Because mybatis used in Camunda-BM-Spring-Starter uses 3.5.3 but maltCloud uses 3.5.6. So I have a conflict to resolve here. The final POM configuration is as follows
<properties>
    <maven.compiler.source>8</maven.compiler.source>
    <maven.compiler.target>8</maven.compiler.target>
    <camunda.spring-boot.version>7.13.0</camunda.spring-boot.version>
</properties>
<dependencies>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
    </dependency>
    <dependency>
        <groupId>com.github.zxhtom</groupId>
        <artifactId>org.components.datasource</artifactId>
        <version>${project.version}</version>
        <exclusions>
            <exclusion>
                <groupId>javax.servlet</groupId>
                <artifactId>servlet-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.camunda.bpm.springboot</groupId>
        <artifactId>camunda-bpm-spring-boot-starter-webapp</artifactId>
        <version>${camunda.spring-boot.version}</version>
    </dependency>
    <dependency>
        <groupId>org.camunda.bpm.springboot</groupId>
        <artifactId>camunda-bpm-spring-boot-starter-rest</artifactId>
        <version>${camunda.spring-boot.version}</version>
    </dependency>
    <dependency>
        <groupId>org.camunda.bpm.springboot</groupId>
        <artifactId>camunda-bpm-spring-boot-starter</artifactId>
        <version>${camunda.spring-boot.version}</version>
        <exclusions>
            <exclusion>
                <groupId>org.mybatis</groupId>
                <artifactId>mybatis</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

</dependencies>
Copy the code
  • Maltcloud is an enterprise-level development framework designed by the author. It is still under development and will be open source in a suitable time. Here I introduced the datasource module from the MaltCloud platform. This module introduces the configuration of Mybatis. Readers can remove this paragraph to configure their own Mybatis can.

Details added

Related version Documents

  • Select a version using Options. The specified version can be downloaded in the Installation Procedure. Click on it and you’ll see a list of smaller versions. Because we chose 7.13.0 in MaltCloud. So we downloaded the corresponding platform camunda.