IBM Developer

Tutorial

Integrating Kafka with Sterling Order Management

Guide to integrate Apache Kafka with IBM Sterling Order Management system, covering installation, configuration, and both synchronous and asynchronous messaging implementations

By Mohamed Jawahar Hussain, Pallavi Sinha

In today’s fast-paced digital landscape, integrating systems and ensuring seamless data flow is essential for business success. This tutorial focuses on integrating Apache Kafka with IBM Sterling Order Management System (OMS), providing a comprehensive guide for developers and system integrators. By leveraging Kafka’s robust messaging capabilities, businesses can enhance their order management processes, improve operational efficiency, and gain real-time insights into their data streams.

This tutorial walks you through the installation and configuration of Apache Kafka and the implementation of both synchronous and asynchronous messaging flows within the Sterling OMS. You will learn how to set up Kafka topics, manage message handling, and utilize the Kafka Transport Component to interact with data streams effortlessly. Whether you are looking to streamline your order fulfillment processes or seeking to enhance your system integration strategies, this guide will equip you with the necessary skills and knowledge to effectively utilize the power of Kafka in your OMS environment.

Installing OpenJDK for Apache Kafka runtime

Apache Kafka is a Java-based application that requires a JDK. You can use any supported version of JDK. In this tutorial, we will use OpenJDK, available in the Linux yum repository.

  1. If you plan to install Kafka as a non-root user, switch to root and run the following command:

    yum install -y java
    
  2. Verify the Java installation by running:

    java -version

    You should see an output similar to this:

     openjdk version "11.0.20.1" 2023-08-24 LTS
     OpenJDK Runtime Environment (Red_Hat-11.0.20.1.1-2) (build 11.0.20.1+1-LTS)
     OpenJDK 64-Bit Server VM (Red_Hat-11.0.20.1.1-2) (build 11.0.20.1+1-LTS, mixed mode, sharing)
    
  3. After confirming the installation, exit from the root user.

Installing Apache Kafka

  1. Download the required version of Apache Kafka from Kafka download or use the following curl command:

    curl -o kafka.tgz https://downloads.apache.org/kafka/3.8.0/kafka_2.13-3.8.0.tgz
    

    In this example, the file is downloaded to /home/admin.

  2. Extract the downloaded file:

     tar -xvf kafka.tgz
    
  3. Rename the extracted directory for simplicity:

     mv kafka_2.13-3.8.0 kafka
    
  4. Navigate to the Kafka directory:

    cd /home/admin/kafka

  5. Start Zookeeper by navigating to the bin directory and running the following command:

     nohup ./zookeeper-server-start.sh /home/admin/kafka/config/zookeeper.properties > /home/admin/kafka/zookeeper.log & disown
    

    Check the log file (/home/admin/kafka/zookeeper.log) to ensure Zookeeper is running. By default, Zookeeper runs on port 2181. Make sure the port is accessible.

  6. Start the Kafka server by running:

     nohup ./kafka-server-start.sh /home/admin/kafka/config/server.properties > /home/admin/kafka/server.log & disown
    

    Verify that the Kafka server is running by checking the log file (/home/admin/kafka/server.log). The Kafka server runs on port 9092 by default. Ensure this port is also accessible.

Creating a Kafka topic

To create a Kafka topic, run the following command:

./kafka-topics.sh --create --topic OMSTOPIC0 --bootstrap-server localhost:9092

If the topic is successfully created, you will see the message:

Created topic OMSTOPIC0.

Testing the Kafka setup

  1. To listen for incoming messages, navigate to /home/admin/kafka/bin and run the following command:

     ./kafka-console-consumer.sh --bootstrap-server 9.30.211.227:9092 --topic OMTOPIC0
    
  2. Execute the following code to post a message. If the message is successfully received by the Kafka topic, it should appear in the console from the previous step:

     package com.kafka;
     import java.io.IOException;
     import java.util.Properties;
     import org.apache.kafka.clients.producer.KafkaProducer;
     import org.apache.kafka.clients.producer.ProducerRecord;
    
     public class KafkaProducerApp
     {
        public static void main(String[] args) throws IOException
        {
           Properties props = new Properties();
           props.put("bootstrap.servers", "9.30.211.227:9092");
           props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
           props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
           try
             {
                 KafkaProducer<String, String> producer = new KafkaProducer<>(props);
                 ProducerRecord<String, String> record = new ProducerRecord<>("OMTOPIC0", "sample message");
                 producer.send(record);
                 producer.flush();
                 producer.close();
                 System.out.println("Message sent !!");
             }
           catch (Exception e)
             {
                 e.printStackTrace();
             }
        }
     }
    

Configuring Sterling OMS to post messages to Kafka topic via a synchronous service

Starting from OMS Fix Pack v10 10.0.2309.0, Kafka client jars are bundled with the product. These can be found in the Sterling OMS jar/kafka directory. The following two jars are included as part of the Kafka component:

  • slf4j-api-1.7.21.jar
  • kafka-clients-3.2.1.jar

Steps to configure Kafka component

  1. Go to Applications -> Application Platform -> Process Modelling. Click on Order Fulfillment, then select Services.

  2. Name the service KafkaProducer.

    Create a synchronous service Figure: Create a synchronous service

  3. Design the flow to handle message posting, as depicted in the Kafka producer service (refer to figure below).

    KafkaProducer service. Figure: Kafka producer service

Kafka configuration options

You can configure Kafka in two ways:

  1. Through a Configuration Group: Use pass-through properties under the property vendor of Kafka by adding them in the customer_overrides.properties file as key-value pairs. The syntax is:

    kafka.cgrp.<config_group_id>.producer.<config_key>=<config_value>
    

    For example, to set bootstrap.servers for a group called mastergroup, use:

    kafka.cgrp.mastergroup.producer.bootstrap.servers=9.30.211.227:9092
    

    Set mastergroup as the "Config Group Id" under the General tab.

  2. This kafka property can also be set using SMA Console using property management under kafka category.

    SMA Property.png Figure: Setting Kafka Property using SMA property management

  3. Directly in the Kafka producer component: Alternatively, the same properties can be configured directly in the Kafka producer component in Sterling Application Manager.

    Note: If no Kafka configuration is provided either as a pass-through property or at the service level, Kafka will use its default configuration values. For more information on default values, refer to IBM Kafka Configuration Documentation

Setting up Kafka configuration:

  1. Under the Kafka Configuration tab, set bootstrap.servers to 9.30.211.227:9092 (refer to the Bootstrap configuration in figure below).

    Bootstrap configuration Figure: Bootstrap configuration.

  2. Ensure that kafka-console-consumer is running on the Kafka server.

Posting a message via KafkaProducer service:

  1. Use an API tester to call the KafkaProducer service with a message. If successfully posted, the message should appear in the Kafka console consumer.

    Posting message to Kafka. Figure: Posting message to Kafka topic

  2. To confirm, run the following command on the Kafka server:

    ./kafka-console-consumer.sh --bootstrap-server 9.30.211.227:9092 --topic OMTOPIC0

    You should see an output like:

    [admin@labmachoine bin]$ ./kafka-console-consumer.sh --bootstrap-server 9.30.211.227:9092 --topic OMTOPIC0
    <?xml version="1.0" encoding="UTF-8"?>
    <Items>
        <Item AdjustmentType="ABSOLUTE" ItemID="IBMItem1"
            ProductClass="Good" Quantity="1000" ShipNode="IBMStore1"
            SupplyType="ONHAND" UnitOfMeasure="EACH"/>
    </Items>
    

Event integration

  1. The KafkaProducer service can now be used in other transactions, such as events.

  2. Implement the necessary event, mapping the service in the event configuration (see figure below).

    Event configuration Figure: Event configuration

  3. Map this event to the ON_SUCCESS event of the createOrder API.

    ON_SUCCESS event of createOrder API Figure: ON_SUCCESS event of createOrder API

  4. After making a createOrder API call, verify that the ON_SUCCESS event message is posted to Kafka.

Configuring Sterling OMS to post messages to Kafka topic via an asynchronous flow

To configure Sterling Order Management System (OMS) to post messages to a Kafka topic via an asynchronous flow, follow these steps:

  1. Create an asynchronous service with a JMS receiver.

    Asynchronous Service Figure: Asynchronous service JMS receiver.

  2. Configure the integration server to handle the asynchronous flow.

    Integration server Figure: Integration server

  3. Set up exception handling to ensure the flow handles any errors during execution.

    Exception Figure: Exception settings

  4. In the flow, configure the system to invoke the createOrder API call.

    createOrder API call Figure: createOrder API call

  5. Configure the Kafka topic where the messages will be posted.

    Kafka Configuration (Topic) Figure: Kafka configuration (Topic)

  6. Ensure that the correct Kafka host is configured for message posting.

    Kafka Configuration (host) Figure: Kafka configuration (Host)

Flow execution

  • The JMS Receiver on the Integration Server picks up the createOrder XML from DEV.QUEUE.1.

  • It then calls the out-of-the-box (OOB) createOrder API.

  • On successful execution of the API, the output will be posted to the configured Kafka topic.

Summary

This tutorial provided comprehensive details on the OMS Sterling Kafka Transport Component, which enables interaction with Kafka data streams without the need for custom code. Application developers can expedite their API development by creating simple services instead of writing extensive custom code.

The tutorial covered:

  • Installation steps for Apache Kafka
  • Configuration of Kafka topics
  • Implementation of both synchronous and asynchronous message handling
  • Setting up integration servers to consume messages from queues and post them to topics

Currently, only outbound integration with Kafka is available. However, the Kafka Receiver component is in the pipeline and will soon enable reading messages from Kafka topics.