0

I am trying to create a Kafka Producer in karaf 4.0.3.

ClassLoader currentLoader; 
try{
    currentLoader = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(null);
    Properties props = new Properties();
    props.put("bootstrap.servers","localhost:9092");
    props.put("value.serializer","org.apache.kafka.common.serialization.StringSerializer");
    props.put("key.serializer","org.apache.kafka.common.serialization.IntegerSerializer");

    KafkaProducer<String,String> producer = new KafkaProducer<String,String>(props);
    Thread.currentThread().setContextClassLoader(currentLoader);
    producer.close();

My pom.xml contains,

<dependency>
    <groupId>org.apache.kafka</groupId>
    <artifactId>kafka-clients</artifactId>
    <version>0.9.0.0</version>
</dependency>   

While deploying the code, I am getting the below error,

2016-05-09 14:18:12,127 | ERROR | nsole user karaf | ShellUtil                        | 44 - org.apache.karaf.shell.core - 4.0.3 | Exception caught while executing command
org.apache.karaf.shell.support.MultiException: Error executing command on bundles:
Error starting bundle143: Activator start error in bundle KafkaArtifact [143].
at org.apache.karaf.shell.support.MultiException.throwIf(MultiException.java:61)
at org.apache.karaf.bundle.command.BundlesCommand.doExecute(BundlesCommand.java:69)[24:org.apache.karaf.bundle.core:4.0.3]
at org.apache.karaf.bundle.command.BundlesCommand.execute(BundlesCommand.java:54)[24:org.apache.karaf.bundle.core:4.0.3]
at org.apache.karaf.shell.impl.action.command.ActionCommand.execute(ActionCommand.java:83)[44:org.apache.karaf.shell.core:4.0.3]
at org.apache.karaf.shell.impl.console.osgi.secured.SecuredCommand.execute(SecuredCommand.java:67)[44:org.apache.karaf.shell.core:4.0.3]
at org.apache.karaf.shell.impl.console.osgi.secured.SecuredCommand.execute(SecuredCommand.java:87)[44:org.apache.karaf.shell.core:4.0.3]
at org.apache.felix.gogo.runtime.Closure.executeCmd(Closure.java:480)[44:org.apache.karaf.shell.core:4.0.3]
at org.apache.felix.gogo.runtime.Closure.executeStatement(Closure.java:406)[44:org.apache.karaf.shell.core:4.0.3]
at org.apache.felix.gogo.runtime.Pipe.run(Pipe.java:108)[44:org.apache.karaf.shell.core:4.0.3]
at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:182)[44:org.apache.karaf.shell.core:4.0.3]
at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:119)[44:org.apache.karaf.shell.core:4.0.3]
at org.apache.felix.gogo.runtime.CommandSessionImpl.execute(CommandSessionImpl.java:94)[44:org.apache.karaf.shell.core:4.0.3]
at org.apache.karaf.shell.impl.console.ConsoleSessionImpl.run(ConsoleSessionImpl.java:270)[44:org.apache.karaf.shell.core:4.0.3]
at java.lang.Thread.run(Thread.java:745)[:1.8.0_66]
Caused by: java.lang.Exception: Error starting bundle143: Activator start error in bundle KafkaArtifact [143].
at org.apache.karaf.bundle.command.BundlesCommand.doExecute(BundlesCommand.java:66)[24:org.apache.karaf.bundle.core:4.0.3]
... 12 more
Caused by: org.osgi.framework.BundleException: Activator start error in bundle KafkaArtifact [143].
at org.apache.felix.framework.Felix.activateBundle(Felix.java:2276)[org.apache.felix.framework-5.4.0.jar:]
at org.apache.felix.framework.Felix.startBundle(Felix.java:2144)[org.apache.felix.framework-5.4.0.jar:]
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:998)[org.apache.felix.framework-5.4.0.jar:]
at org.apache.karaf.bundle.command.Start.executeOnBundle(Start.java:38)[24:org.apache.karaf.bundle.core:4.0.3]
at org.apache.karaf.bundle.command.BundlesCommand.doExecute(BundlesCommand.java:64)[24:org.apache.karaf.bundle.core:4.0.3]
... 12 more
Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.apache.kafka.clients.producer.ProducerConfig
at org.apache.kafka.clients.producer.KafkaProducer.<init>(KafkaProducer.java:181)
at com.KafkaSample.KafkaArtifact.Producer.<init>(Producer.java:24)
at com.KafkaSample.KafkaArtifact.KafkaConsumerProducerDemo.start(KafkaConsumerProducerDemo.java:9)
at org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:697)
at org.apache.felix.framework.Felix.activateBundle(Felix.java:2226)
... 16 more

I have tried workaround in the below link as well,

Karaf - Kafka OSGI bundle - Producer issue

But still getting the same error.

Community
  • 1
  • 1
Sanjeev
  • 208
  • 1
  • 2
  • 10

1 Answers1

0

I know its a 3 months old question. Even i got stuck with this producer issue. After digging for 2 days i stumbled upon a jira issue where someone has already mentioned this issue and the resolution has been patched but will be available in the 2.18.0 version of the camel library. To resolve this however, what i did was to clone this camel repository and build the components i wanted for my project.These components are at 2.18.0-SNAPSHOT version at this time. Under the components folder select the components you want and execute maven clean package to get the jar generated in the target directory.

One additional thing, when you compile camel-core sub project. It executes a lot of test cases, which you might not be needing it, so just replace "" with "org/apache/camel/**/*.java" in the last line of properties. Hope this helps.