Pārlūkot izejas kodu

优化http节点

caixiaofeng 6 mēneši atpakaļ
vecāks
revīzija
e4a65d1317

+ 4 - 0
flow-common/flow-common-flowable-starter/pom.xml

@@ -20,6 +20,10 @@
     </properties>
 
     <dependencies>
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpclient</artifactId>
+        </dependency>
         <!-- flowable -->
         <dependency>
             <groupId>org.flowable</groupId>

+ 26 - 14
flow-workflow/flow-workflow-entity/src/main/java/com/flow/entity/node/HttpNode.java

@@ -1,6 +1,7 @@
 package com.flow.entity.node;
 
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
+import com.flow.enums.TimeUnitEnum;
 import com.google.common.collect.Lists;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
@@ -18,8 +19,10 @@ public class HttpNode extends Node {
     private String method;
     private Map<String, Object> headers;
     private Map<String, Object> requestBody;
-    private Boolean ignoreException = false;
     private Long requestTimeout = 0L;
+    private Integer retryCount;
+    private TimeUnitEnum unit = TimeUnitEnum.MINUTE;
+    private Integer duration;
 
 
     @Override
@@ -30,8 +33,8 @@ public class HttpNode extends Node {
         httpServiceTask.setType("http");
         httpServiceTask.setName(this.getName());
         httpServiceTask.setExecutionListeners(this.buidEventListener());
-        httpServiceTask.setAsynchronous(false);
-        httpServiceTask.setParallelInSameTransaction(true);
+        // httpServiceTask.setAsynchronous(true);
+        // httpServiceTask.setParallelInSameTransaction(true);
         // httpServiceTask.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION);
         // httpServiceTask.setImplementation("${httpDelegate}");
         // 请求参数
@@ -56,10 +59,6 @@ public class HttpNode extends Node {
             bodyExtension.setExpression(this.requestBody.toString());
             fieldExtensions.add(bodyExtension);
         }
-        FieldExtension ignoreExtension = new FieldExtension();
-        ignoreExtension.setFieldName("ignoreException");
-        ignoreExtension.setStringValue(this.ignoreException.toString());
-        fieldExtensions.add(ignoreExtension);
         FieldExtension timeoutExtension = new FieldExtension();
         timeoutExtension.setFieldName("requestTimeout");
         timeoutExtension.setStringValue(this.requestTimeout.toString());
@@ -79,15 +78,28 @@ public class HttpNode extends Node {
         FieldExtension activityBehaviorExtension = new FieldExtension();
         activityBehaviorExtension.setFieldName("httpActivityBehaviorClass");
         activityBehaviorExtension.setStringValue("com.flow.behavior.CustomHttpServiceTaskActivityBehavior");
-        // fieldExtensions.add(activityBehaviorExtension);
+        fieldExtensions.add(activityBehaviorExtension);
         httpServiceTask.setFieldExtensions(fieldExtensions);
         // 失败重试
-        ExtensionElement retryElement = new ExtensionElement();
-        retryElement.setNamespace("https://flowable.org/model");
-        retryElement.setNamespacePrefix("flowable");
-        retryElement.setName("failedJobRetryTimeCycle");
-        retryElement.setElementText("R5/PT5M");
-        // httpServiceTask.addExtensionElement(retryElement);
+        boolean isRetry = Objects.nonNull(this.retryCount) && this.retryCount > 0;
+        FieldExtension ignoreExtension = new FieldExtension();
+        ignoreExtension.setFieldName("ignoreException");
+        ignoreExtension.setStringValue(Boolean.toString(isRetry));
+        fieldExtensions.add(ignoreExtension);
+        if (isRetry) {
+            StringBuilder retry = new StringBuilder();
+            retry.append(String.format("R%s", this.retryCount));
+            if (Objects.nonNull(this.duration)) {
+                retry.append("/")
+                        .append(String.format(this.unit.getUnit(), this.duration));
+                ExtensionElement retryElement = new ExtensionElement();
+                retryElement.setNamespace("https://flowable.org/model");
+                retryElement.setNamespacePrefix("flowable");
+                retryElement.setName("failedJobRetryTimeCycle");
+                retryElement.setElementText(retry.toString());
+                httpServiceTask.addExtensionElement(retryElement);
+            }
+        }
         elements.add(httpServiceTask);
         // 下一个节点的连线
         Node child = this.getChild();