In the era of saas craze, workflow seems to be a professional quality

Posted by shwanky on Sun, 12 Dec 2021 09:34:18 +0100

preface

  • Now more and more projects begin to use workflow to meet their daily work. Today, let's take a look at the workflow of Activiti. Let's start with BPMN painting

Environment installation

  • BPMN documents about processes are mainly integrated through eclipse development tools. The idea is mainly painted by actiBPM, but actiBPM is no longer maintained after 2014. Now it can not be directly installed and used in the new idea version.
  • In that case, you can develop an idea project and draw it through eclipse, but this situation seems troublesome. Here we recommend another integration tool to draw BPMN process diagram
  • Camunda modeler is a third-party process design tool. Its advantage is that instead of eclipse, we can load it through the External Tools of idea.

  • We can draw the rest.

extend

  • Most of the third-party process drawing software similar to camunda will be provided to the community office. They are started as java services. Why do you need this way? Because in this way, we can draw the process through camunda by calling the api. It can be drawn in our own process platform. In this way, the process plotter is connected to our own platform system.

Release process

  • First, we draw a simple process through camunda. Above, we first launch a camunda platform in the form of tomcat to release our production process.

Service task

  • First of all, the action of swiping card for payment is a server operation. Here, we click the settings bar on the right to set the server service mode

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

gateway

  • Now our process is still very simple. Above, we set the Implementation method to External, which means that the node is jointly implemented with the help of External services and specifies the message subject topic. For message listening, we monitor the information in Java. Another important role in the process is the gateway. The gateway here is our judgment node. For example, there is a demand for credit card payment requests above
  • Payment approval is required when the payment amount is greater than or equal to 1000 yuan. If it is less than 1000 yuan, payment can be made directly.
  • There is one in camunda × The graph of is what we call gateway. Let's modify the flow chart a little

  • We can drag the gateway directly. Its feature is that there are two or more branches. So which branch will go eventually requires us to set conditions on each branch. Here we set the conditions through Java expressions.

  • amount this is a variable. You can define this variable at will, but it must be provided at the beginning of the process, otherwise an error will be reported

  • We can ask the user to provide the necessary information of the process before the gateway starts

  • Then the process will be reversed according to the amount filled in. Payment approval needs to be approved according to the process information, so I also added the item parameter to fill in the application form. Why add this parameter? If I am the person in charge of approving payment. But I don't care much about the amount of money, or I have no brain to pass some projects. At this time, we can realize the automatic approval of this node with the help of the automatic decision-making 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 the icon in the upper left corner to set the rules

  • Our rules are very simple. I will approve any item XYZ project, otherwise it will not be approved.

  • In this rule, we can set many ways, and our above is the only way, that is, each condition is mutually exclusive, either black or white. There are other ways we can debug ourselves

  • In returning to our main process, we select the Implementation method as DMN, and ref select the id of the DMN we set above

Java monitoring 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.6.1</version>
</dependency>
<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.3.1</version>
</dependency>
Copy code
  • After we add dependencies here, we start listening to the external services in the process corresponding to the topic of our process
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 locking time is 20 seconds, which is modified to 1 second here
        .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 code
  • Now we can check the log,

Maltcloud integration

  • Workflow is scheduled in phase II in the maltcloud version plan, so I plan to develop workflow related operations after the basic functions of maltcloud are completed. The first is process drawing. The basic drawing and publishing of process have been mentioned above. Let's take a look at how to inherit workflow into our enterprise framework maltcloud.
  • Note that the springboot and camunda versions need to match during integration. The official website provides us with a matching scheme for 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.
  • Used with maltcloud is 2.2 2. Release version, we can locate camunda springboot starter. The version should be 3.4 x; Then we go to maven warehouse to check the relevant versions

  • Here I chose to use 3.4 Version of 0. Later, it was found that 2.2 x. Release's springboot also supports 7.13 x. Final decision to use 7.13 0 this version.

  • Because mybatis used in camunda BPM spring starter uses 3.5 3 but 3.5.0 is used in maltcloud Version 6. So I still need to solve the conflict 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 code
  • Maltcloud is an enterprise level development framework designed by the author. It is still in the development stage for the time being and will be open source in the appropriate period. Here I introduce the datasource module in the maltcloud platform. This module mainly introduces the configuration of mybatis. Readers can remove this paragraph and configure mybatis by themselves.

Detail supplement

Related version documents

  • Select the version through options. You can download the specified version in the Installation Procedure. After clicking in, there will be a list of small versions. Because we chose 7.13 in maltcloud 0 So we download the corresponding platform camunda

Topics: Java Eclipse data structure Programmer intellij-idea