Downstream Rest API based Custom Event Consumer Configuration

Using the downstream rest API, customers can implement this configuration and route the processed data to handle their detected events.

For publishing events through downstream rest api, follow the steps below:
  1. In the acme/etc/producer_config.properties file, update the IP address of Kafka server.
  2. In the drive.json file, update the corresponding parameters in the eventConsumers section:
    1. the className parameter with the name of the Java class.
    2. the parameters > name parameter with name of the downstream system.
  3. In the restServiceUri field, update the appropriate REST URI, and in the restServiceHeaderContentType field, update the MediaType to be set to the header.
  4. Update the following database parameters values with the values from the drive.json file:
    1. databaseServerIp: update it with database server IP address.
    2. databaseServerPort: update it with database server port.
    3. databaseServerUser: update it with database server userName.
    4. databaseServerPassword: update it with database server userPassword.
  5. Add other downstream specific parameter to this sample json.
  6. In the eventEndpoints parameters, add the endpoint name.
    Note: The value of APPLICATION_ENDPOINT_NAME should match with the event consumer class.
  7. After updating the values, ensure maven is installed on the server.
To build the jar for the custom_event_consumer, follow the steps below:
  1. Navigate to the HCL Detect installation folder.
  2. Change directory to custom_event_consumer using the below command.
    cd custom_event_consumer/
  3. By default, the custom_event_consumer folder contains the following makefile, which to can create and move the custom event consumer jar file to installer path "/tomcat/webapps/drive/WEB-INF/lib/".
    .PHONY: build move clean all
    all: build move clean
    build: 
    	mvn -f pom-custom.xml clean install
    move:
    	cp target/custom_event_consumer-*.jar $(HCL_INSTANCE_HOME)/tomcat/webapps/drive/WEB-INF/lib/
    clean:
    	rm -rf target
  4. To execute the makefile, use the following command.
    “make”
  5. On Successful executing the makefile, the jar of the custom_event_consumer is moved to tomcat.
The sample configuration of downstream Kafka publishing events is shown below:
"eventConsumers": [
	{
                "className": "com.detect.SampleRestBasedEventConsumer",
                "name": "SampleRestBasedEventConsumer",
                "parameters": [
                    {
                        "name": "databaseServerIp",
                        "stringValue": "127.0.0.1"
                    },
                    {
                        "name": "databaseServerUser",
                        "stringValue": "drive"
                    },
                    {
                        "name": "databaseServerPassword",
                        "stringValue": "6F2FA7F6B3CD1570F19F0A0B2636E033"
                    },
                    {
                        "name": "databaseServerPort",
                        "int32Value": 3306
                    },
                    {
                        "name": "databaseName",
                        "stringValue": "drive_acme_core"
                    },
                    {
                        "name": "restServiceHeaderContentType",
                        "stringValue": "application/json"
                    },
                    {
                        "name": "restServiceUri",
                        "stringValue": "http://httpbin.org/post"
                    }
                ]
            }
]
  1. eventConsumers.className: set the name of the Java class responsible for writing events in the pre-defined format of the downstream system.
  2. eventConsumers.name: name of the downstream system intended to assign.
  3. Parameters:
    1. Database related:
      1. databaseServerIp: Server IP of the database to publish downstream events to.
      2. databaseServerUser: Username of the database credentials.
      3. databaseServerPassword: Encrypted password of the database credentials.
      4. databaseServerPort: Port of the database.
      5. databaseName: Name of the database.
    2. Rest related:
      1. restServiceHeaderContentType: MediaType to be set to the header.
      2. restServiceUri: URL of the Rest API.
Sample RestBasedEventConsumer.java

This Java class writes the events in the pre-defined format of the downstream system to implement the EventConsumer interface and its methods.

  • initialize() - this method creates a database & downstream REST connection.
  • consumeEvent() - this method receives the event object.
  • consumeEventImpl() - this method sets database message, downstream payload message and writes the respective message to database and send to downstream rest API.
Note: For future references, relating to new Detect version releases, please ensure to update the value of properties to "detect.version" & "detect.foundation.version", in the pom-custom.xml file, to the appropriate version number.