Chapter 10. Replicating audit data in a JMS message broker

You can replicate KIE Server audit data to a Java Message Service (JMS) message broker, for example ActiveMQ or Artemis, and then dump the data in an external database schema so that you can improve the performance of your Spring Boot application by deleting the audit data from your application schema.

If you configure your application to replicate data in a message broker, when an event occurs in KIE Server the record of that event is stored in the KIE Server database schema and it is sent to the message broker. You can then configure an external service to consume the message broker data into an exact replica of the application’s database schema. The data is appended in the message broker and the external database every time an event is produce by KIE Server.

Note

Only audit data is stored in the message broker. No other data is replicated.

Prerequisites

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

Procedure

  1. Open the Spring Boot application’s pom.xml file in a text editor.
  2. Add the KIE Server Spring Boot audit dependency to the pom.xml file:

    <dependency>
      <groupId>org.kie</groupId>
      <artifactId>kie-server-spring-boot-autoconfiguration-audit-replication</artifactId>
      <version>${version.org.kie}</version>
    </dependency>
  3. Add the dependency for your JMS client. The following example adds the Advanced Message Queuing Protocol (AMQP) dependency:

    <dependency>
      <groupId>org.amqphub.spring</groupId>
      <artifactId>amqp-10-jms-spring-boot-starter</artifactId>
      <version>2.2.6</version>
    </dependency>
  4. Add the JMS pool dependency:

    <dependency>
      <groupId>org.messaginghub</groupId>
      <artifactId>pooled-jms</artifactId>
    </dependency>
  5. To configure KIE Server audit replication to use queues, complete the following tasks:

    1. Add the following lines to your Spring Boot application’s application.properties file:

      kieserver.audit-replication.producer=true
      kieserver.audit-replication.queue=audit-queue
    2. Add the properties required for your message broker client. The following example shows how to configure KIE Server for AMPQ, where <JMS_HOST_PORT> is the port that the broker listens on and <USERNAME> and <PASSWORD are the login credentials for the broker:

      amqphub.amqp10jms.remote-url=amqp://<JMS_HOST_PORT>
      amqphub.amqp10jms.username=<USERNAME>
      amqphub.amqp10jms.password=<PASSWORD>
      amqphub.amqp10jms.pool.enabled=true
    3. Add the following lines to the application.properties file of the service that will consume the message broker data:

      kieserver.audit-replication.consumer=true
      kieserver.audit-replication.queue=audit-queue
    4. Add the properties required for your message broker client to the application.properties file of the service that will consume the message broker data. The following example shows how to configure KIE Server for AMPQ, where <JMS_HOST_PORT> is the port that your message broker listens on and <USERNAME> and <PASSWORD> are the login credentials for the message broker:

      amqphub.amqp10jms.remote-url=amqp://<JMS_HOST_PORT>
      amqphub.amqp10jms.username=<USERNAME>
      amqphub.amqp10jms.password=<PASSWORD>
      amqphub.amqp10jms.pool.enabled=true
  6. To configure KIE Server audit replication to use topics, complete the following tasks:

    1. Add the following lines to your Spring Boot application’s application.properties file:

      kieserver.audit-replication.producer=true
      kieserver.audit-replication.topic=audit-topic
    2. Add the properties required for your message broker client to the application.properties file of the service that will consume the message broker data. The following example shows how to configure KIE Server for AMPQ, where <JMS_HOST_PORT> is the port that your message broker listens on and <USERNAME> and <PASSWORD are the login credentials for the message broker:

      spring.jms.pub-sub-domain=true
      amqphub.amqp10jms.remote-url=amqp://<JMS_HOST_PORT>
      amqphub.amqp10jms.username=<USERNAME>
      amqphub.amqp10jms.password=<PASSWORD>
      amqphub.amqp10jms.pool.enabled=true
    3. Add the following lines to the application.properties file of the service that will consume the message broker data:

      kieserver.audit-replication.consumer=true
      kieserver.audit-replication.topic=audit-topic::jbpm
      kieserver.audit-replication.topic.subscriber=jbpm
      spring.jms.pub-sub-domain=true
    4. Add the properties required for your message broker client to the application.properties file of the service that will consume the message broker data. The following example shows how to configure KIE Server for AMPQ, where <JMS_HOST_PORT> is the port that your message broker listens on and <USERNAME> and <PASSWORD> are the login credentials for the message broker:

      amqphub.amqp10jms.remote-url=amqp://<JMS_HOST_PORT>
      amqphub.amqp10jms.username=<USERNAME>
      amqphub.amqp10jms.password=<PASSWORD>
      amqphub.amqp10jms.pool.enabled=true
      amqphub.amqp10jms.clientId=jbpm
  7. Optional: To configure the KIE Server that contains the replicated data to be read only, set the org.kie.server.rest.mode.readonly property in the application.properties file to true:

    org.kie.server.rest.mode.readonly=true

10.1. Spring Boot JMS audit replication parameters

The following table describes the parameters used to configure JMS audit replication for Red Hat Process Automation Manager applications on Spring Boot.

Table 10.1. Spring Boot JMS audit replication parameters

ParameterValuesDescription

kieserver.audit-replication.producer

true, false

Specifies whether the business application will act as a producer to replicate and send the JMS messages to either a queue or a topic.

kieserver.audit-replication.consumer

true, false

Specifies whether the business application will act as a consumer to receive the JMS messages from either a queue or a topic.

kieserver.audit-replication.queue

string

The name of the JMS queue to either send or consume messages.

kieserver.audit-replication.topic

string

The name of the JMS topic to either send or consume messages.

kieserver.audit-replication.topic.subscriber

string

The name of the topic subscriber.

org.kie.server.rest.mode.readonly

true, false

Specifies read only mode for the business application.