pulsar icon indicating copy to clipboard operation
pulsar copied to clipboard

Pulsar Functions not working in LocalRunner (2.5.0)

Open yfathi opened this issue 6 years ago • 4 comments

Describe the bug Pulsar Function are not working with LocalRunner To Reproduce Steps to reproduce the behavior:

  1. Create a Function

import org.apache.pulsar.functions.api.Context;
import org.apache.pulsar.functions.api.Function;
public class CounterFunction implements Function<String, String> {
    @Override
    public String process(String input, Context context) {
        Arrays.asList(input.split("\\s+")).forEach(word -> context.incrCounter(word, 1));
        return input;
    }
}

  1. Create a LocalRunner

import org.apache.pulsar.common.functions.FunctionConfig;
import org.apache.pulsar.functions.LocalRunner;


import java.util.Collections;

public class CounterRunner {

    public static void main(String[] args) throws Exception {

        FunctionConfig functionConfig = new FunctionConfig();
        functionConfig.setName("counter");
        functionConfig.setInputs(Collections.singleton("input"));
        functionConfig.setClassName(CounterFunction.class.getName());
        functionConfig.setRuntime(FunctionConfig.Runtime.JAVA);
        functionConfig.setOutput("output");

        LocalRunner localRunner = LocalRunner.builder().functionConfig(functionConfig).build();
        localRunner.start(true);
    }

  1. Start a Local Pulsar Instance Or Configure Local Runner to Connect to your Pusar LocalRunner localRunner = LocalRunner.builder().functionConfig(functionConfig).brokerServiceUrl("pulsar://PORT:PORT").build();

  2. Execute : and see Error :

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/pulsar/functions/runtime/shaded/io/netty/util/Timer
	at org.apache.pulsar.client.impl.ClientBuilderImpl.build(ClientBuilderImpl.java:62)
	at org.apache.pulsar.functions.runtime.thread.ThreadRuntimeFactory.createPulsarClient(ThreadRuntimeFactory.java:96)
	at org.apache.pulsar.functions.runtime.thread.ThreadRuntimeFactory.<init>(ThreadRuntimeFactory.java:67)
	at org.apache.pulsar.functions.LocalRunner.startThreadedMode(LocalRunner.java:405)
	at org.apache.pulsar.functions.LocalRunner.start(LocalRunner.java:319)
	at com.functions.CounterRunner.main(CounterRunner.java:24)
Caused by: java.lang.ClassNotFoundException: org.apache.pulsar.functions.runtime.shaded.io.netty.util.Timer
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
	... 6 more
[INFO ] 2020-02-06 10:43:49.132 [Thread-0] LocalRunner - Shutting down the localrun runtimeSpawner ...

Process finished with exit code 1

Expected behavior

Pulsar Function works and consumer input topic / produce into output topic

Desktop (please complete the following information):

  • OS: Windows
  • IDE : Intellij 2019.3
  • Java : 11
  • dependencies { implementation group: 'org.apache.pulsar', name: 'pulsar-functions-local-runner', version: '2.5.0' }

Additional context IT works in the previous version (2.4.0)

  • dependencies { implementation group: 'org.apache.pulsar', name: 'pulsar-functions-local-runner', version: '2.4.0' }

yfathi avatar Feb 06 '20 09:02 yfathi

Are there any workaround this? We really need to test locally and LocalRunner was very helpful. Thanks!

psilos avatar May 04 '20 17:05 psilos

Ok, you can get around it by using pulsar-functions-local-runner-original instead which doesn't include shaded dependencies.

psilos avatar May 04 '20 20:05 psilos

+1

whisper-bye avatar May 22 '20 03:05 whisper-bye

Closed as stale. Please create a new issue if it's still relevant to the maintained versions.

tisonkun avatar Dec 09 '22 14:12 tisonkun