camunda系列教程3(外部任务客户端)

官方示例:

启动camunda

https://blog.csdn.net/weixin_44213308/article/details/120609758https://blog.csdn.net/weixin_44213308/article/details/120609758

官方资源

https://download.csdn.net/download/weixin_44213308/30620140https://download.csdn.net/download/weixin_44213308/30620140

bpm文件

camunda系列教程3(外部任务客户端)_第1张图片



  
    
      SequenceFlow_0fn07fk
    
    
      SequenceFlow_187qbq7
      SequenceFlow_0ilu8bp
      SequenceFlow_1axd8hr
    
    
      SequenceFlow_1axd8hr
    
    
    
    
    
      
        
          
          
          
        
      
      SequenceFlow_0di0jwo
      SequenceFlow_0foxe2y
    
    
      SequenceFlow_0fn07fk
      SequenceFlow_0ilu8bp
      SequenceFlow_0di0jwo
    
    
      ${amount<1000}
    
    
      SequenceFlow_0foxe2y
      SequenceFlow_187qbq7
      SequenceFlow_0ypgah8
    
    
      ${approved}
    
    
      ${amount>=1000}
    
    
      SequenceFlow_0ypgah8
    
    
      ${!approved}
    
  
  
    
      
        
        
        
          
        
      
      
        
        
        
        
          
        
      
      
        
        
        
          
        
      
      
        
        
        
          
        
      
      
        
        
        
          
        
      
      
        
        
        
          
        
      
      
        
        
        
          
        
      
      
        
        
          
        
      
      
        
      
      
        
        
          
        
      
      
        
      
      
        
        
          
        
      
      
        
        
          
        
      
      
        
        
          
        
      
    
  

新建外部Java程序

pom文件


	4.0.0

	org.camunda.bpm.getstarted
	charge-card-worker
	0.0.1-SNAPSHOT

	
		7.15.0
		1.8
		1.8
	
	
		
			org.camunda.bpm
			camunda-external-task-client
			${camunda.external-task-client.version}
		
		
			org.slf4j
			slf4j-simple
			1.6.1
		
		
			javax.xml.bind
			jaxb-api
			2.3.1
		
	

	
		
			jdk9-plus
			(1.8,)
			
				
					com.sun.xml.bind
					jaxb-impl
					2.3.1
				
			
		
	

Java代码(修改:添加账户和密码

package org.camunda.bpm.getstarted.chargecard;

import java.awt.Desktop;
import java.net.URI;
import java.util.logging.Logger;

import org.camunda.bpm.client.ExternalTaskClient;
import org.camunda.bpm.client.backoff.ExponentialBackoffStrategy;
import org.camunda.bpm.client.interceptor.auth.BasicAuthProvider;

public class ChargeCardWorker {
	private final static Logger LOGGER = Logger.getLogger(ChargeCardWorker.class.getName());

	public static void main(String[] args) {
		ExternalTaskClient client = ExternalTaskClient.create()
				.baseUrl("http://localhost:82/engine-rest")
				// long polling timeout
				.asyncResponseTimeout(10000)
				// Only change made after turning on basic auth
				.addInterceptor(new BasicAuthProvider("superAdmin","123456"))
				.backoffStrategy(new ExponentialBackoffStrategy(0, 0, 0))
				.build();

		// subscribe to an external task topic as specified in the process
		client.subscribe("charge-card")
				// the default lock duration is 20 seconds, but you can override this
				.lockDuration(1000)
				.handler((externalTask, externalTaskService) -> {
					// Put your business logic here

					// Get a process variable
					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();
	}
}

访问camunda web页面,启动任务

camunda系列教程3(外部任务客户端)_第2张图片

 camunda系列教程3(外部任务客户端)_第3张图片

 camunda系列教程3(外部任务客户端)_第4张图片

你可能感兴趣的:(工作流,camunda,java,spring,boot)