Chapter 5. Red Hat Process Automation Manager Spring Boot configuration

After you create your Spring Boot project, you can configure several components to customize your application.

5.1. Configuring REST endpoints for Spring Boot applications

After you create your Spring Boot project, you can configure the host, port, and path for the REST endpoint for your Spring Boot application.

Prerequisites

Procedure

  1. Extract the Spring Boot project ZIP file and navigate to the <BUSINESS-APPLICATION>/<BUSINESS-APPLICATION>-service/src/main/resources folder, where <BUSINESS-APPLICATION> is the name of your Spring Boot project.
  2. Open the application.properties file in a text editor.
  3. Configure the host, port, and path for the REST endpoints, where <ADDRESS> is the server address and <PORT> is the server port:

    server.address=<ADDRESS>
    server.port=<PORT>
    cxf.path=/rest

    The following example adds the REST endpoint to the address localhost on port 8090.

    server.address=localhost
    server.port=8090
    cxf.path=/rest

5.2. Configuring the KIE Server identity

After you create your Spring Boot project, you can configure KIE Server so that it can be easily identified.

Prerequisites

  • You have a Spring Boot business application ZIP file that you created using the business application website.

Procedure

  1. Extract the Spring Boot project ZIP file and navigate to the <BUSINESS-APPLICATION>/<BUSINESS-APPLICATION>-service/src/main/resources folder, where <BUSINESS-APPLICATION> is the name of your Spring Boot project.
  2. Open the application.properties file in a text editor.
  3. Configure the KIE Server parameters as shown in the following example:

    kieserver.serverId=<BUSINESS-APPLICATION>-service
    kieserver.serverName=<BUSINESS-APPLICATION>-service
    kieserver.location=http://localhost:8090/rest/server
    kieserver.controllers=http://localhost:8080/business-central/rest/controller

    The following table describes the KIE Server parameters that you can configure in your business project:

    Table 5.1. kieserver parameters

    ParameterValuesDescription

    kieserver.serverId

    string

    The ID used to identify the business application when connecting to the Process Automation Manager controller.

    kieserver.serverName

    string

    The name used to identify the business application when it connects to the Process Automation Manager controller. Can be the same string used for the kieserver.serverId parameter.

    kieserver.location

    URL

    Used by other components that use the REST API to identify the location of this server. Do not use the location as defined by server.address and server.port.

    kieserver.controllers

    URLs

    A comma-separated list of controller URLs.

5.3. Integrating Apache Kafka with your Red Hat Process Automation Manager Spring Boot project

Apache Kafka is a distributed data streaming platform that can publish, subscribe to, store, and process streams of records in real time. It is designed to handle data streams from multiple sources and deliver them to multiple consumers. Apache Kafka is an alternative to a traditional enterprise messaging system.

You can integrate Apache Kafka with your Red Hat Process Automation Manager Spring Boot project.

Prerequisites

  • You have an existing Red Hat Process Automation Manager Spring Boot project.

Procedure

  1. In your Spring Boot project directory, open the business-application-service/src/main/resources/application.properties file.
  2. Add the kieserver.kafka.enabled system property with value true:

    kieserver.kafka.enabled=true

5.4. Configuring KIE Server components to start at runtime

If you selected Business Automation when you created your Spring Boot business application, you can specify which KIE Server components must start at runtime.

Prerequisites

  • You have a Spring Boot business application ZIP file that you created using the business application website.

Procedure

  1. Extract the Spring Boot project ZIP file and navigate to the <BUSINESS-APPLICATION>/<BUSINESS-APPLICATION>-service/src/main/resources folder, where <BUSINESS-APPLICATION> is the name of your Spring Boot project.
  2. Open the application.properties file in a text editor.
  3. To set a component to start at runtime, set the value of the component to true.

    The following table lists the components that you can set to start at runtime:

    Table 5.2. kieserver capabilities parameters

    ParameterValuesDescription

    kieserver.drools.enabled

    true, false

    Enables or disables the Decision Manager component.

    kieserver.dmn.enabled

    true, false

    Enables or disables the Decision Model and Notation (DMN) component.

    kieserver.jbpm.enabled

    true, false

    Enables or disables the Red Hat Process Automation Manager component.

    kieserver.jbpmui.enabled

    true, false

    Enables or disables the Red Hat Process Automation Manager UI component.

    kieserver.casemgmt.enabled

    true, false

    Enables or disables the case management component.

5.5. Configuring your Spring Boot application for asynchronous execution

After you create your Spring Boot project, you can use the jbpm.executor parameters to enable asynchronous execution.

Prerequisites

  • You have a Spring Boot business application ZIP file that you created using the business application website.

Procedure

  1. Extract the Spring Boot project ZIP file and navigate to the <BUSINESS-APPLICATION>/<BUSINESS-APPLICATION>-service/src/main/resources folder, where <BUSINESS-APPLICATION> is the name of your Spring Boot project.
  2. Open the application.properties file in a text editor.
  3. To enable asynchronous execution, set the value of the jbpm.executor.enabled parameter to true, uncomment the other jbpm.executor parameters, and change the values as required, as shown in the following example:

    jbpm.executor.enabled=true
    jbpm.executor.retries=5
    jbpm.executor.interval=0
    jbpm.executor.threadPoolSize=1
    jbpm.executor.timeUnit=SECONDS

    The following table describes the executor parameters that you can configure in your business project:

    Table 5.3. Executor parameters

    ParameterValuesDescription

    jbpm.executor.enabled

    true, false

    Disables or enables the executor component.

    jbpm.executor.retries

    integer

    Specifies the number of retries if errors occur while a job is running.

    jbpm.executor.interval

    integer

    Specifies the length of time that the executor uses to synchronize with the database. The unit of time is specified by the jbpm.executor.timeUnit parameter. Disabled by default (value 0).

    jbpm.executor.threadPoolSize

    integer

    Specifies the thread pool size.

    jbpm.executor.timeUnit

    string

    Specifies the time unit used to calculate the interval that the executor uses to synchronize with the database. The value must be a valid constant of java.util.concurrent.TimeUnit. The default value is SECONDS.

5.6. Configuring the business application for a cluster using Quartz

If you plan to run your application in a cluster, you must configure the Quartz timer service.

Prerequisites

  • You have a business application that you created using the business application website and you want to use this application in a cluster.

Procedure

  1. Create the quartz.properties file and add the following content:

    #============================================================================
    # Configure Main Scheduler Properties
    #============================================================================
    org.quartz.scheduler.instanceName = SpringBootScheduler
    org.quartz.scheduler.instanceId = AUTO
    org.quartz.scheduler.skipUpdateCheck=true
    org.quartz.scheduler.idleWaitTime=1000
    #============================================================================
    # Configure ThreadPool
    #============================================================================
    org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
    org.quartz.threadPool.threadCount = 5
    org.quartz.threadPool.threadPriority = 5
    #============================================================================
    # Configure JobStore
    #============================================================================
    org.quartz.jobStore.misfireThreshold = 60000
    org.quartz.jobStore.class=org.quartz.impl.jdbcjobstore.JobStoreCMT
    org.quartz.jobStore.driverDelegateClass=org.jbpm.process.core.timer.impl.quartz.DeploymentsAwareStdJDBCDelegate
    org.quartz.jobStore.useProperties=false
    org.quartz.jobStore.dataSource=myDS
    org.quartz.jobStore.nonManagedTXDataSource=notManagedDS
    org.quartz.jobStore.tablePrefix=QRTZ_
    org.quartz.jobStore.isClustered=true
    org.quartz.jobStore.clusterCheckinInterval = 5000
    #============================================================================
    # Configure Datasources
    #============================================================================
    org.quartz.dataSource.myDS.connectionProvider.class=org.jbpm.springboot.quartz.SpringConnectionProvider
    org.quartz.dataSource.myDS.dataSourceName=quartzDataSource
    org.quartz.dataSource.notManagedDS.connectionProvider.class=org.jbpm.springboot.quartz.SpringConnectionProvider
    org.quartz.dataSource.notManagedDS.dataSourceName=quartzNotManagedDataSource
    Note

    Data source names in the Quartz configuration file refer to Spring beans. The connection provider must be set to org.jbpm.springboot.quartz.SpringConnectionProvider to enable integration with Spring-based data sources.

  2. To enable the Quartz clustered timers and set the path of the quartz.properties file that you created in the previous step, include the following properties in the <BUSINESS-APPLICATION>/<BUSINESS-APPLICATION>-service/src/main/resourcesapplication.properties file, where <BUSINESS-APPLICATION> is the name of your Spring Boot project.

    jbpm.quartz.enabled=true
    jbpm.quartz.configuration=quartz.properties
  3. Create a managed and an unmanaged data source by adding the following content to the <BUSINESS-APPLICATION>/<BUSINESS-APPLICATION>-service/src/main/resources/application.properties file:

    # enable to use database as storage
    jbpm.quartz.db=true
    
    quartz.datasource.name=quartz
    quartz.datasource.username=sa
    quartz.datasource.password=sa
    quartz.datasource.url=jdbc:h2:./target/spring-boot-jbpm;MVCC=true
    quartz.datasource.driver-class-name=org.h2.Driver
    
    # used to configure connection pool
    quartz.datasource.dbcp2.maxTotal=15
    
    # used to initialize quartz schema
    quartz.datasource.initialization=true
    spring.datasource.schema=classpath*:<QUARTZ_TABLES_H2>.sql
    spring.datasource.initialization-mode=always

    In the preceding example, replace <QUARTZ_TABLES_H2> with the name of a Quartz H2 database schema script. The last three lines of the preceding configuration initialize the database schema.

By default, Quartz requires two data sources:

  • Managed data source to participate in the transaction of the decision engine or process engine
  • Unmanaged data source to look up timers to trigger without any transaction handling

Red Hat Process Automation Manager business applications assume that the Quartz database (schema) will be co-located with Red Hat Process Automation Manager tables and therefore produce data sources used for transactional operations for Quartz.

The other (non transactional) data source must be configured but it should point to the same database as the main data source.

5.7. Configuring business application user group providers

With Red Hat Process Automation Manager, you can manage human-centric activities. To provide integration with user and group repositories, you can use two KIE API entry points:

  • UserGroupCallback: Responsible for verifying whether a user or group exists and for collecting groups for a specific user
  • UserInfo: Responsible for collecting additional information about users and groups, for example email addresses and preferred language

You can configure both of these components by providing alternative code, either code provided out of the box or custom developed code.

For the UserGroupCallback component, retain the default implementation because it is based on the security context of the application. For this reason, it does not matter which backend store is used for authentication and authorisation (for example, RH-SSO). It will be automatically used as a source of information for collecting user and group information.

The UserInfo component is a separate component because it collects more advanced information.

Prerequisites

  • You have a ZIP file that you created using the business application website and that contains a business automation project.

Procedure

  1. To provide an alternative implementation of UserGroupCallback, add the following code to the Application class or a separate class annotated with @Configuration:

    @Bean(name = "userGroupCallback")
    public UserGroupCallback userGroupCallback(IdentityProvider identityProvider) throws IOException {
        return new MyCustomUserGroupCallback(identityProvider);
    }
  2. To provide an alternative implementation of UserInfo, add the following code to the Application class or a separate class annotated with @Configuration:

    @Bean(name = "userInfo")
    public UserInfo userInfo() throws IOException {
        return new MyCustomUserInfo();
    }

5.8. Configuring a Spring Boot project with a MySQL or PostgreSQL database

Red Hat Process Automation Manager business applications are generated with the default H2 database. You can change the database type to MySQL or PostgreSQL.

Prerequisites

Procedure

  1. Extract the Spring Boot project ZIP file and navigate to the <BUSINESS-APPLICATION>/<BUSINESS-APPLICATION>-service/src/main/resources folder, where <BUSINESS-APPLICATION> is the name of your Spring Boot project.
  2. Open the application.properties file in a text editor.
  3. Configure your Spring Boot project to use a MySQL or PostgreSQL, complete one of the following set of steps:

    1. To configure your business application to use a MySQL database, locate the following parameters in the application.properties file and change the values as shown:

      spring.datasource.username=jbpm
      spring.datasource.password=jbpm
      spring.datasource.url=jdbc:mysql://localhost:3306/jbpm
      spring.datasource.driver-class-name=com.mysql.jdbc.jdbc2.optional.MysqlXADataSource
      
      spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
    2. To configure your business application to use a PostgreSQL database, locate the following parameters in the application.properties file and change the values as shown:

      spring.datasource.username=jbpm
      spring.datasource.password=jbpm
      spring.datasource.url=jdbc:postgresql://localhost:5432/jbpm
      spring.datasource.driver-class-name=org.postgresql.xa.PGXADataSource
      
      spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
      Note

      To create a PostgreSQL schema that uses the bytea column type instead of the oid column type, set the value of the org.kie.persistence.postgresql.useBytea property to true:

      org.kie.persistence.postgresql.useBytea=true
  4. Save the application.properties file.

5.9. Configuring business applications for JPA

The Java Persistence API (JPA) is a standard technology that enables you to map objects to relational databases. You must configure JPA for your Red Hat Process Automation Manager business application.

Prerequisites

Procedure

  1. Extract the <BUSINESS-APPLICATION>.zip file and navigate to the <BUSINESS-APPLICATION>/<BUSINESS-APPLICATION>-service/src/main/resources folder, where <BUSINESS-APPLICATION> is the name of your Spring Boot project.
  2. Open the application.properties file in a text editor.
  3. Locate the following parameters in the application.properties file and verify that they have the values shown:

    spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect
    spring.jpa.properties.hibernate.show_sql=false
    spring.jpa.properties.hibernate.hbm2ddl.auto=update
    spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
  4. If your business application has business automation capabilities, you can add entities to the entity manager factory by adding a comma-separated list of packages:

    spring.jpa.properties.entity-scan-packages=org.jbpm.springboot.samples.entities

    Business applications with business automation capabilities create an entity manager factory based on the persistence.xml file that comes with Red Hat Process Automation Manager. All entities found in the org.jbpm.springboot.samples.entities package are automatically added to the entity manager factory and used the same as any other JPA entity in the application.

Additional resources

For more information about configuring JPA, see the Spring Boot Reference Guide.

5.10. Configuring pluggable variable persistence

You can provide an arbitrary entity manager for configured process variable persistence in your Red Hat Process Automation Manager Spring Boot application. To do this, add named beans during the object marshalling strategy resolution. This enables you to configure a second entity manager factory based on a second data source qualifier. Note that this configuration will not interfere with the primary data source.

Prerequisites

  • You have an existing Red Hat Process Automation Manager Spring Boot project.

Procedure

  1. Add a customized entity manager JavaBean to your java class. The following example shows an entity manager Java Bean called auditEntityManager for a Java Persistence API (JPA) data source:

        @Bean(name = "auditEntityManager")
        @ConditionalOnMissingBean(name = "auditEntityManager")
        public LocalContainerEntityManagerFactoryBean entityManagerFactory(@Qualifier("jpaAuditDataSource") DataSource dataSource, JpaProperties jpaProperties) {
            return EntityManagerFactoryHelper.create(applicationContext,
                                                     dataSource,
                                                     jpaProperties,
                                                     "custom-persistent-unit",
                                                     "classpath:/META-INF/persistence.xml");
        }

    The auditEntityManager becomes an implicit context parameter when the parameters are resolved during MVFLEX Expression Language (MVEL) evaluation.

  2. Add the following marshalling stragegy to the kie-deployment-descriptor.xml file:

     <marshalling-strategy>
        <resolver>mvel</resolver>
        <identifier>new org.drools.persistence.jpa.marshaller.JPAPlaceholderResolverStrategy(auditEntityManager)
        </identifier>
        <parameters/>
        </marshalling-strategy>

Additional resources

  • For more information about persistence, see the "Persisting process variables in a separate database schema in Red Hat Process Automation Manager" section in Managing and monitoring KIE Server.

5.11. Enabling Swagger documentation

You can enable Swagger-based documentation for all endpoints available in the service project of your Red Hat Process Automation Manager business application.

Prerequisites

Procedure

  1. Extract the <BUSINESS-APPLICATION>.zip file and navigate to the <BUSINESS-APPLICATION>/<BUSINESS-APPLICATION>-service folder, where <BUSINESS-APPLICATION> is the name of your Spring Boot project.
  2. Open the service project pom.xml file in a text editor.
  3. Add the following dependencies to the service project pom.xml file and save the file.

    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-rs-service-description-swagger</artifactId>
      <version>3.2.6</version>
    </dependency>
    <dependency>
      <groupId>io.swagger</groupId>
      <artifactId>swagger-jaxrs</artifactId>
      <version>1.5.15</version>
      <exclusions>
        <exclusion>
          <groupId>javax.ws.rs</groupId>
          <artifactId>jsr311-api</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
  4. To enable the Swagger UI (optional), add the following dependency to the pom.xml file and save the file.

    <dependency>
      <groupId>org.webjars</groupId>
      <artifactId>swagger-ui</artifactId>
      <version>2.2.10</version>
    </dependency>
  5. Open the <BUSINESS-APPLICATION>/<BUSINESS-APPLICATION>-service/src/main/resources/application.properties file in a text editor.
  6. Add the following line to the application.properties file to enable Swagger support:

    kieserver.swagger.enabled=true

After you start the business application, you can view the Swagger document at http://localhost:8090/rest/swagger.json. The complete set of endpoints is available at http://localhost:8090/rest/api-docs?url=http://localhost:8090/rest/swagger.json.