NoClassDefFoundError - Trying to add producer to the kafka module

I am trying to add producer functions to the community kafka module because we want to start pushing data to a central DB.

i am using JDK 11 and Ignition SDk 8.1.7 with the intelliJ IDE.

The functions I am adding at first look like this:

package org.ignitionmdc.apache.kafka;
import com.inductiveautomation.ignition.client.gateway_interface.ModuleRPCFactory;

import java.util.List;
import java.util.Map;


public class Kafka_Com {

    public static List<Map> getConsumer(String address, String topic, String groupname) {
        KafkaRPC rpc = ModuleRPCFactory.create("org.ignitionmdc.apache.kafka.kafka", KafkaRPC.class);
        return rpc.RPCGetConsumer(address,topic,groupname);
    }

    public static List<Map> getSSLConsumer(String address, String topic, String groupname) {
        KafkaRPC rpc = ModuleRPCFactory.create("org.ignitionmdc.apache.kafka.kafka", KafkaRPC.class);
        return rpc.RPCGetSSLConsumer(address,topic,groupname);
    }

    public static String createProducer(String address){
        KafkaRPC rpc = ModuleRPCFactory.create("org.ignitionmdc.apache.kafka.kafka", KafkaRPC.class);
        return rpc.RPCCreateProducer(address);
    }

    public static boolean transmitData(String producerKey, String topic, String data){
        KafkaRPC rpc = ModuleRPCFactory.create("org.ignitionmdc.apache.kafka.kafka", KafkaRPC.class);
        return rpc.RPCTransmitData(producerKey, topic, data);
    }
}

When I first made the module and loaded it into Ignition I could see the new functions in the doc string but I was greeted with a swath of red error text the first time I tried to call “createProducer”. I then moved back into the IDE and used the “mainTest” script as follows:

package org.ignitionmdc.apache.kafka;

public class mainTest {
    public static void main(String[] args) {
        Kafka_Com inst = new Kafka_Com();

        String c = inst.createProducer("127.0.0.1:9092");
        System.out.println(c);
    }
}

The error I get is:

Exception in thread "main" java.lang.NoClassDefFoundError: com/inductiveautomation/ignition/client/gateway_interface/ModuleRPCFactory

I will of course continue to research on my own but meanwhile if anyone has faced similar I’ll appreciate any advice you can offer. Full disclosure its my 2nd day of working with java.

Thanks,

Nick

Don’t mistake this answer for me knowing anything about this module because I just cloned it for the first time.

I’m not sure what IDE you are using, but in IntelliJ you need to enable this option on your run configuration:

All of the Ignition SDK dependencies are marked as “provided” scope in the Maven pom files, which basically means “these are provided by the environment I will run in, so I need them to compile against but don’t need to package them for runtime”.

@Kevin.Herron thanks for the response, I did manage to get it working today.

Here is what the API looks like:

Here is what the usage looks like in Ignition:

And my local kafka instance subscribing to the message and getting it successfully.

I would say that even with my super minimal java experience (can count the days on 1 hand) the Ignition SDK, docs, and examples make it possible to do some really cool stuff, so thanks for the help.

Onwards, we want to start streaming all data (alarms, audit, and tag history) to a central repository that uses a column based database. One of the use cases would be to have a computation in a central location, for example OEE. We will have hundreds of gateways when we are fully built out and if we want to adjust existing code on the edge, it becomes impractical.

Another question is that for tag data we know we can get a split data stream. Do you have any recommendations where to start looking to pick up alarms and audit, other than querying the on-prem DB?

Thanks,

Nick