²Î¿¼:Camunda ¿ìËÙÈëÃÅ¡¢Camunda SpringBootÓë½ø½×ÄÚÈÝ¡¢camundaÖÐÎÄÕ¾¡¢camunda¹Ù·½Ó¢ÎÄÎĵµ
ʹÓÃÁ÷³Ì
1¡¢ÏÂÔغͰ²×°
ÔÚ¼ÆËã»úÉÏ°²×°Camunda BPMƽ̨ºÍCamunda Modeler(ÓÃÓÚ±à¼Á÷³Ìͼ¼°ÆäËûÄ£ÐÍ)¡£
Camunda ModelerÏÂÔصØÖ· https://camunda.com/download/modeler/ ¡£
2¡¢±à¼Á÷³Ì
н¨BPMNÁ÷³Ì ¡ª¡ª> ±à¼ ¡ª¡ª> ÅäÖÃÁ÷³Ì²ÎÊý ¡ª¡ª> ±£´æÉú³É .bpmn Îļþ ¡ª¡ª> ÓÃjava»ònodeʵÏÖÈÎÎñ
Service Task(·þÎñÈÎÎñ) , ·þÎñÀàÐÍÓкܶàÖ´Ðеķ½·¨,±ÈÈç¡°external(Íⲿ)¡±ÈÎÎñģʽ ¡£
User Task(È˹¤ÈÎÎñ)
ÅäÖÃÍⲿÈÎÎñ:
ÅäÖÃÁ÷³Ì²ÎÊý:
±àдÖ÷ÀàʵÏÖÒµÎñÂß¼,´úÂë´óÖÂÈçÏÂ:
import java.util.logging.Logger;
import java.awt.Desktop;
import java.net.URI;
import org.camunda.bpm.client.ExternalTaskClient;
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:8080/engine-rest")
.asyncResponseTimeout(10000)
.build();
client.subscribe("charge-card")
.lockDuration(1000)
.handler((externalTask, externalTaskService) -> {
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();
}
externalTaskService.complete(externalTask);
})
.open();
}
}
- ´úÂëÖеÄ
"http://localhost:8080/engine-rest" ¶ÔÓ¦ÏÂÃ沿ÊðÁ÷³ÌÖеÄREST Endpoint ¡£(×¢Òâµã)
3¡¢²¿ÊðÁ÷³Ì
½«²¿ÊðÁ÷³Ìµ½Á÷³ÌÒýÇæ,È»ºó·¢ÆðÁ÷³Ì,¼ì²éÁ÷³ÌÊÇ·ñ·¢Æð³É¹¦ ¡£
ʹÓà Camunda Modeler ²¿ÊðÁ÷³Ì
µã»÷¹¤¾ßÀ¸ÖеIJ¿Êð°´Å¥¿ÉÒÔ½«µ±Ç°Á÷³Ì²¿Êðµ½Á÷³ÌÒýÇæ,µã»÷²¿Êð°´Å¥,ÊäÈëDeployment Name Ϊ ¡°Payment¡± ,ÊäÈëÏ·½REST Endpoint Ϊhttp://localhost:8080/engine-rest ,È»ºóµã»÷ÓÒϽÇDeploy²¿Êð:
ʹÓÃCockpit²é¿´²¿Êð½á¹û
´´½¨Á÷³ÌʵÀý(·¢ÆðÁ÷³Ì)
ʹÓÃRest API·¢ÆðÁ÷³Ì,ËùÒÔÐèÒªÒ»¸ö½Ó¿Ú²âÊÔ¹¤¾ß(ÀýÈç:Postman),»òÕßÒ²¿ÉÒÔʹÓõçÄÔ×Ô´øµÄcurl
a) curl
ÔÚÃüÁîÐÐÖÐÖ´ÐÐ
curl -H "Content-Type: application/json" -X POST -d '{"variables": {"amount": {"value":555,"type":"long"}, "item": {"value":"item-xyz"} } }' http://localhost:8080/engine-rest/process-definition/key/payment-retrieval/start
"http://localhost:8080/engine-rest" ¶ÔÓ¦´úÂëÖеÄbaseUrl;process-definition payment-retrieval ¶ÔÓ¦¡°¸¶¿îÁ÷³Ì¡±id
Èç¹ûÄÜ¿´µ½³É¹¦µÄ·µ»Ø½á¹û,ÔòÁ÷³Ì·¢Æð³É¹¦¡£
b)Postman
ÔÚurlÖÐÊäÈë http://localhost:8080/engine-rest/process-definition/key/payment-retrieval/start
ģʽѡÔñPOST
µã»÷Body,Ñ¡Ôñraw ,²¢ÔÚÓÒÃæÑ¡Ôñapplication/json
È»ºóÊäÈëBodyÄÚÈÝ:
{
"variables": {
"amount": {
"value":555,
"type":"long"
},
"item": {
"value": "item-xyz"
}
}
}
±à¼Íê³Éºó,½á¹ûÕâÑù:
µã»÷ Send ·¢ËÍÇëÇó
Èç¹ûÄÜ¿´µ½³É¹¦µÄ·µ»Ø½á¹û,ÔòÁ÷³Ì·¢Æð³É¹¦
4¡¢È˹¤ÈÎÎñ
Á˽⽫È˹¤ÈÎÎñ¼¯³Éµ½Á÷³ÌÖеĻù´¡ÖªÊ¶,ÒÔ¼°ÈçºÎʹÓÃCamunda¹¹½¨±íµ¥¡£
Ìí¼ÓÈ˹¤ÈÎÎñ½Úµã¡°Åú×¼¸¶¿î¡±:
ÅäÖÃÈ˹¤ÈÎÎñ±íµ¥:
µã»÷¡°Åú×¼¸¶¿î½Úµã¡±,ÔÚÓÒ²àµÄÊôÐÔÃæ°åÖеã»÷Forms(±íµ¥)Ñ¡Ï,µã»÷ÏÂÃæµÄ¼ÓºÅ,Ìí¼Ó3¸öÊôÐÔ:
ÊôÐÔ1:
- ID: amount
- Type: long
- Label: ½ð¶î
ÊôÐÔ2:
- ID: item
- Type: string
- Label: 씀ÊôÐÔ3:
- ID: approved
- Type: boolean
- Label: ÊÇ·ñͬÒâ?
·¢ÆðÁ÷³Ì:
²¿ÊðÁ÷³Ìºó,´ò¿ªÈÎÎñÁбí(http://localhost:8080/camunda/app/tasklist/),ʹÓà demo / demo µÇ¼
µã»÷ÓÒÉÏ½ÇµÄ Start process ,ÔÚµ¯³öµÄ¶Ô»°¿òÖÐÑ¡Ôñ¡°¸¶¿îÁ÷³Ì¡±
Õâʱ»áµ¯³ö±à¼Á÷³Ì±äÁ¿µÄ¶Ô»°¿ò,¿ÉÒÔͨ¹ýµã»÷ Add a variable °´Å¥Ìí¼Ó±äÁ¿,Õâ´ÎÎÒÃÇÏȲ»Ìí¼Ó,Ö±½Óµã»÷ÓÒÏÂ½Ç Start Æô¶¯Á÷³Ì(×¢Òâµã)
Õâʱ,ÔÚÈÎÎñÁбíÓ¦¸Ã¾ÍÄÜ¿´µ½¸Õ´´½¨µÄÈ˹¤ÈÎÎñÁË,Èç¹ûûÓпÉÒÔÊÖ¶¯Ë¢ÐÂÒ»ÏÂ
²¿·ÖÓû§ÕâÀï¿´²»µ½,¿ÉÄÜÊÇ All Tasks ¹ýÂËÆ÷ûÓÐ×Ô¶¯Ìí¼Ó,×ó²àÏÔʾΪ:
Õâʱµã»÷ Add a simple filter ¼´¿É
Ñ¡ÔñÕâ¸öÈÎÎñÏî,ÔÚÓÒ²à¿ÉÒÔ¿´µ½±íµ¥
µã»÷ Diagram Ñ¡Ï,¿ÉÒÔ¿´µ½¸ßÁÁµÄ½Úµã¾ÍÊǵ±Ç°½øÐÐÖеĽڵã
5¡¢¶¯Ì¬ÐÔ(Íø¹Ø)
Á˽âÈçºÎͨ¹ýÏòÁ÷³ÌÌí¼ÓÍø¹ØÀ´Ê¹Á÷³Ì¸ü¾ß¶¯Ì¬ÐÔ¡£
ÅÅËûÍø¹Ø(Exclusive Gateways)
Ìí¼ÓÍø¹Ø(ÁâÐÎ)²¢½øÐÐÅäÖÃ:
±ÈÈç,
Ñ¡Ôñ¡°<1000¡±µÄÁ¬Ïß,´ò¿ªÊôÐÔÃæ°å,Ñ¡Ôñ¡°Condition Type¡±Îª¡°Expression¡±,ÕâÀïÎÒÃÇʹÓÃJAVAͳһ±í´ïʽÓïÑÔ±àдÌõ¼þ,ÕâÀïÒª×öµÄÊÇÔÚ½ð¶îСÓÚ1000ʱֱ½ÓË¢¿¨¸¶¿î,ÔòÊäÈë±í´ïʽ ${amount<1000} :
´ò¿ªÈÎÎñÁбí(http://localhost:8080/camunda/app/tasklist/),ʹÓà demo / demo µÇ¼
µã»÷ÓÒÉÏ½ÇµÄ Start process ,ÔÚµ¯³öµÄ¶Ô»°¿òÖÐÑ¡Ôñ¡°¸¶¿îÁ÷³Ì¡±
ÔÚÉÏÒ»ÕÂÖÐ,ÎÒÃÇÖ±½Óµã»÷ Start,µ«Õâ´ÎÎÒÃÇÒªÔö¼Ó¼¸¸ö±äÁ¿À´²âÊÔ¶¯Ì¬µÄÁ÷³Ì(¹Ø¼üµã)
ÊÔןü¸Ä amount µÄÖµ,²é¿´¶ÔÁ÷³ÌÖ´ÐÐ˳ÐòµÄÓ°Ïì¡£
6¡¢¾ö²ß×Ô¶¯»¯
Á˽âÈçºÎÔÚÁ÷³ÌÖм¯³ÉDMN¾ö²ß±í¡£
camunda+springboot
ÔÚÁ÷³ÌÖе÷Óà JAVA Class
ͨ¹ýformÑ¡ÏÌí¼Ó±íµ¥ ¡ª¡ª> Ìí¼Óservice taskµ½Á÷³ÌÖÐ ¡ª¡ª> ±àдjavaÀà ¡ª¡ª> ÅäÖÃservice task ¡ª¡ª> Æô¶¯ÐÂÁ÷³Ì
webÓ¦ÓóÌÐò (Tasklist, Cockpit, Admin, Rest Api ½Ó¿Ú )
- REST API REST APIÔÊÐíÄãʹÓÃÔ¶³ÌÓ¦ÓûòJavaScriptÓ¦ÓõÄÁ÷³ÌÒýÇæ¡£ (×¢Òâ:REST APIµÄÎĵµÒѳÉΪ×Ô¼ºµÄÎĵµ¡£)
- Camunda Tasklist ÓÃÓÚÈ˹¤Á÷¹ÜÀíºÍÓû§ÈÎÎñµÄWebÓ¦ÓÃ,ÔÊÐíÁ÷³Ì²ÎÓëÕß¼ì²éÆ乤×÷Á÷ÈÎÎñ²¢µ¼º½µ½ÈÎÎñ±íµ¥,ÒÔ±ãÔÚÈÎÎñÉϹ¤×÷²¢ÌṩÊý¾ÝÊäÈë¡£
- Camunda Cockpit ÓÃÓÚ¹ý³Ì¼àÊӺͲÙ×÷µÄWebÓ¦ÓÃ,ÔÊÐíÄãËÑË÷Á÷³ÌʵÀý,¼ì²éÆä״̬²¢ÐÞ¸´Ë𻵵ÄʵÀý¡£
- Camunda Admin ÔÊÐíÄã¹ÜÀíÓû§,×éºÍÊÚȨµÄWebÓ¦Óá£
|