Search code examples
scalaapache-kafkaapache-kafka-streamsksqldb

Starting KsqlRestApplication form scala and getting NoSuchMethodError org.apache.kafka.streams.StreamsConfig.getConsumerConfigs


I am trying to write a program that enables me to run predefined KSQL operations on Kafka topics in Scala, but I don't want to open the KSQL Cli everytime. Therefore I want to start the KSQL "Server" from within my Scala program. If I understand the KSQL source code right, I have to build and start a KsqlRestApplication:

def restServer = KsqlRestApplication.buildApplication(new 
KsqlRestConfig(defaultServerProperties), true, new VersionCheckerAgent 
{override def start(ksqlModuleType: KsqlModuleType, properties: 
Properties): Unit = ???})

But when I try doing that, I get the following error:

Exception in thread "main" java.lang.NoSuchMethodError: org.apache.kafka.streams.StreamsConfig.getConsumerConfigs(Ljava/lang/String;Ljava/lang/String;)Ljava/util/Map;
at io.confluent.ksql.rest.server.BrokerCompatibilityCheck.create(BrokerCompatibilityCheck.java:62)
at io.confluent.ksql.rest.server.KsqlRestApplication.buildApplication(KsqlRestApplication.java:241)

I looked into the function call in BrokerCompatibilityCheck and in the create function it calls the StreamsConfig.getConsumerConfigs() with 2 Strings as parameters instead of the parameters defined in

https://kafka.apache.org/0102/javadoc/org/apache/kafka/streams/StreamsConfig.html#getConsumerConfigs(StreamThread,%20java.lang.String,%20java.lang.String).

Are my KSQL and Kafka version simply not compatible or am I doing something wrong? I am using KSQL version 4.1.0-SNAPSHOT and Kafka version 1.0.0.


Solution

  • Yes, NoSuchMethodError typically indicates a version incompatibility between libraries.

    The link you posted is to javadoc for kafka 0.10.2. The method hasn't changed in 1.0 but indeed in the upcoming 1.1 it only takes 2 Strings: https://kafka.apache.org/11/javadoc/org/apache/kafka/streams/StreamsConfig.html#getConsumerConfigs(java.lang.String,%20java.lang.String) . That suggests the version of KSQL you're using (4.1.0-SNAPSHOT) depends on version 1.1 of kafka streams, which is currently in the release candidate phase and I believe and should be out soon:

    https://lists.apache.org/thread.html/780c4458b16590e99261b69d7b41b9ec374a3226d72c8d38885a008a@%3Cusers.kafka.apache.org%3E

    As per that email you can find the latest (1.1.0-rc2) artifacts in the apache staging repo: https://repository.apache.org/content/groups/staging/