0

I am working on a OSGi (apache felix) and maven based micro-service. I am in the process of learning jbpm. I have create a decision table that I need to invoke from my OSGi java project. Below is the code I am using from the javadoc of bpmn but seems like it is not working because although I imported bunch of dependencies from maven, still lot of other dependencies like

KnowledgeBaseConfiguration
ResourceFactoryService
ResourceFactoryService
KnowledgeBase

remain unresolved.

<drools.version>7.0.0.Final</drools.version>
  
  <dependency>
    <groupId>org.jbpm</groupId>
    <artifactId>jbpm-bpmn2</artifactId>
    <version>${drools.version}</version>
  </dependency><!-- https://mvnrepository.com/artifact/org.drools/drools-core -->
  <dependency>
    <groupId>org.drools</groupId>
    <artifactId>drools-core</artifactId>
    <version>${drools.version}</version>
  </dependency><!-- https://mvnrepository.com/artifact/org.drools/drools-osgi-integration --><!-- https://mvnrepository.com/artifact/org.drools/drools-decisiontables -->
  <dependency>
    <groupId>org.drools</groupId>
    <artifactId>drools-decisiontables</artifactId>
    <version>${drools.version}</version>
  </dependency><!-- https://mvnrepository.com/artifact/org.drools/drools-api -->
  <dependency>
    <groupId>org.drools</groupId>
    <artifactId>drools-compiler</artifactId>
    <version>${drools.version}</version>
  </dependency>
  <dependency>
    <groupId>org.kie</groupId>
    <artifactId>kie-api</artifactId>
    <version>${drools.version}</version>
  </dependency>

This is the logic that I found in the document of jbpm in the section of integration with OSGi

    ServiceReference serviceRef = bundleContext.getServiceReference( ServiceRegistry.class.getName() );
    ServiceRegistry registry = (ServiceRegistry) bundleContext.getService( serviceRef );

    KnowledgeBuilderFactoryService knowledgeBuilderFactoryService = registry.get( KnowledgeBuilderFactoryService.class );
    KnowledgeBaseFactoryService knowledgeBaseFactoryService = registry.get( KnowledgeBaseFactoryService.class );
    ResourceFactoryService resourceFactoryService = registry.get( ResourceFactoryService.class );

    KnowledgeBaseConfiguration kbaseConf = knowledgeBaseFactoryService.newKnowledgeBaseConfiguration( null, getClass().getClassLoader() );

    KnowledgeBuilderConfiguration kbConf = knowledgeBuilderFactoryService.newKnowledgeBuilderConfiguration( null, getClass().getClassLoader() );
    KnowledgeBuilder kbuilder = knowledgeBuilderFactoryService.newKnowledgeBuilder( kbConf );
    kbuilder.add( resourceFactoryService.newClassPathResource( "MyProcess.bpmn", Dummy.class ), ResourceType.BPMN2 );

    kbaseConf = knowledgeBaseFactoryService.newKnowledgeBaseConfiguration( null, getClass().getClassLoader() );
    KnowledgeBase kbase = knowledgeBaseFactoryService.newKnowledgeBase( kbaseConf );
    kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );

    StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
    return Optional.empty();

My questions are :

  1. How to integrate jbpm and Osgi java to invoke and execute a bpmn or decision table?
  2. Why are these dependencies unresolved? I tried the latest 7.46.0.FINAL version of drools as well?
Tiya
  • 553
  • 8
  • 26

1 Answers1

0

For the question 1, you need the kie-server-client from group org.kie.server.

Other dependencies that you might use are the definitions in apis(question 2): jbpm-kie-services from group org.jbpm and kie-api, kie-internal from group org.kie.

zhrist
  • 1,169
  • 11
  • 28
  • thanks. is org.kie.server a separate server? I need the decision table deployed and invoked in my microservice's OSGi container. All I need decision table is for giving inputs from my java program and getting output from decision table. Any help is appreciated in this matter. – Tiya Dec 21 '20 at 04:37
  • No, kie-server is not a separate server. It is the server where you execute dmn, bpmn and drools files compiled in kjar. Decision table is also a drool/dmn form. You deploy your kjar(jar with decision table) on kie-server for execution. Can you accept the answer as appropriate? Thanks(ping me for more help if you do not find your way) – zhrist Dec 21 '20 at 12:26
  • thanks. My need is - fox my existing java OSGi microservice running on docker, I want to include the decision table in it, import the maven dependencies and my java program should be able to pass the input to the decision table and get the output from it back into java. I don't think I want another kjar to get included in my microservice. I need everything to run on the same container. Is it possible? – Tiya Dec 21 '20 at 15:25
  • Yes, that is possible. Than just use the ISGi enabled ones: https://docs.jboss.org/jbpm/release/7.46.0.Final/jbpm-docs/html_single/#_osgi – zhrist Dec 21 '20 at 15:57
  • Thanks. I understand jBPM is OSGi compatible . Is there any example that I can refer where only a jbpm decision table is used in an existing container and kserver execution server is not used. I tried finding but no luck, everythwere i see either a jbpm project is created from scratch or it is running in its own kie-container or the server. – Tiya Dec 21 '20 at 16:14
  • It is rare that kie-server is not loaded as execution layer, but it is possible. Look at https://docs.jboss.org/jbpm/release/7.46.0.Final/jbpm-docs/html_single/#_spring_boot_support_for_kie_projects and https://docs.jboss.org/jbpm/release/7.46.0.Final/jbpm-docs/html_single/#_spring_boot_configuration . I feel for Decision table you need to embed only kie-server-spring-boot-starter-drools – zhrist Dec 21 '20 at 19:21