1.pycamunda 简介
Pycamunda是一个用Python语言编写的Camunda BPM平台的客户端库。它可以用于与Camunda BPM引擎进行交互,通过Camunda REST API执行各种操作,如启动流程实例、完成任务等。它提供了一组易于使用的工具,使开发人员可以轻松地与Camunda BPM集成。Pycamunda还提供了一系列例子和文档,以帮助开发人员更好地利用Camunda BPM引擎的功能。
2. pymanuda 进行bpmn部署
from pycamunda import deployment,processdef,processinst,task,user
url = "http://192.168.8.183:8080/engine-rest"
def create_deploy():
#filepath = "diagram_6.bpmn"
filepath = "diagram_1.bpmn"
with open(filepath, "rb") as ff:
content = ff.read()
create_file = deployment.Create(url=url, name=filepath.split(".")[0], )
# file1 = deployment.Create(url=url,name=filepath.split(".")[0],tenant_id="12345690").files
create_file.add_resource(content)
deploy = create_file()
print(deploy)
pro_dic = deploy.deployed_process_definitions
#items = pro_dic.items()
#print(len(pro_dic),pro_dic,type(pro_dic))
for key,value in pro_dic.items():
print(value)
pro_key = value.key
pro_id = value.id_
print(pro_key)
#start_pro = processdef.StartInstance(url=url,key=pro_key,business_key="xxxxx")
start_pro = processdef.StartInstance(url=url, id_=pro_id, business_key="xxxxx")
process1 = start_pro()
processinst.Activate(url=url,id_=process1.id_)
create_deploy()
在以上程序中主要的部署程序为以下几条:
create_file = deployment.Create(url=url, name=filepath.split(".")[0], )
# file1 = deployment.Create(url=url,name=filepath.split(".")[0],tenant_id="12345690").files
create_file.add_resource(content)
deploy = create_file()
这里用到了pycamunda.deployment.Create
不过源码的files属性方法应该改为如下:文章来源:https://uudwc.com/A/edRom
@property
def files(self):
return {f'resource-{i}.bnmp': resource for i, resource in enumerate(self._files)}
因为通过files方法会上传文件,并且把文件命名为resource-i,如果没有.bpmn后缀则无法正常识别。
在完成部署后需要启动进程和实例,完成之后就可以正常执行了。文章来源地址https://uudwc.com/A/edRom