apache / pulsar

Apache Pulsar - distributed pub-sub messaging system
https://pulsar.apache.org/
Apache License 2.0
14.17k stars 3.57k forks source link

java.lang.NoClassDefFoundError: org/apache/pulsar/shade/com/google/common/primitives/Ints #15532

Closed nvmav closed 1 year ago

nvmav commented 2 years ago

I am trying to consume from pulsar topic. But, I am not able to consume. It is throwing NoClassDefFoundError. how can this be resolved?

pulsar client version: 2.10 pulsar server version: 2.10 OS: Ubuntu 20.04.4 LTS installation type: standalone(not docker) java sdk version: 11 & 17

consumer code:

private static void consumeFromPulsarAsync() throws Exception {

    logger.info("consumeFromPulsarAsync()");

    PulsarClient client = PulsarClient.
        builder()
        .serviceUrl("pulsar://localhost:6650")
        .build();

    logger.info("consumeFromPulsarAsync() client");

    Consumer<String> consumer = client.newConsumer(Schema.STRING)
        .topic("persistent://public/default/ack-2")
        .consumerName("pulsar-consumer-id-" + Math.random())
        .subscriptionName("pulsar-subscription-id-" + Math.random())
        .subscriptionType(SubscriptionType.Shared).subscribe();

    logger.info("consumeFromPulsarAsync() consumer");

    consumer.receiveAsync().thenCompose((msg) -> {
      logger.info("consumeFromPulsarAsync() consumed msg :: {}", msg.getValue());
      try {
        consumer.acknowledge(msg);
      } catch (PulsarClientException e) {
        throw new RuntimeException(e);
      }
      return null;
    });
  }

schema for my topic:

{
  "version": 0,
  "schemaInfo": {
    "name": "ack-2",
    "schema": "",
    "type": "STRING",
    "properties": {
      "env": "local"
    }
  }
}

I am seeing below error:

2022-05-10 23:22:36,428 WARN  org.apache.pulsar.client.impl.MultiTopicsConsumerImpl        [] - Encountered error in partition auto update timer task for multi-topic consumer. Another task will be scheduled.
java.lang.NoClassDefFoundError: org/apache/pulsar/shade/com/google/common/primitives/Ints
    at org.apache.pulsar.shade.com.google.common.collect.Lists.computeArrayListCapacity(Lists.java:152) ~[477237be-607e-4d6e-94f3-3cdcfde7bd1b_my.work.manager-release-1.0-jar-with-dependencies.jar:?]
    at org.apache.pulsar.shade.com.google.common.collect.Lists.newArrayListWithExpectedSize(Lists.java:192) ~[477237be-607e-4d6e-94f3-3cdcfde7bd1b_my.work.manager-release-1.0-jar-with-dependencies.jar:?]
    at org.apache.pulsar.client.impl.MultiTopicsConsumerImpl$TopicsPartitionChangedListener.onTopicsExtended(MultiTopicsConsumerImpl.java:1238) ~[477237be-607e-4d6e-94f3-3cdcfde7bd1b_my.work.manager-release-1.0-jar-with-dependencies.jar:?]
    at org.apache.pulsar.client.impl.MultiTopicsConsumerImpl$1.run(MultiTopicsConsumerImpl.java:1350) [477237be-607e-4d6e-94f3-3cdcfde7bd1b_my.work.manager-release-1.0-jar-with-dependencies.jar:?]
    at org.apache.pulsar.shade.io.netty.util.HashedWheelTimer$HashedWheelTimeout.run(HashedWheelTimer.java:715) [477237be-607e-4d6e-94f3-3cdcfde7bd1b_my.work.manager-release-1.0-jar-with-dependencies.jar:?]
    at org.apache.pulsar.shade.io.netty.util.concurrent.ImmediateExecutor.execute(ImmediateExecutor.java:34) [477237be-607e-4d6e-94f3-3cdcfde7bd1b_my.work.manager-release-1.0-jar-with-dependencies.jar:?]
    at org.apache.pulsar.shade.io.netty.util.HashedWheelTimer$HashedWheelTimeout.expire(HashedWheelTimer.java:703) [477237be-607e-4d6e-94f3-3cdcfde7bd1b_my.work.manager-release-1.0-jar-with-dependencies.jar:?]
    at org.apache.pulsar.shade.io.netty.util.HashedWheelTimer$HashedWheelBucket.expireTimeouts(HashedWheelTimer.java:790) [477237be-607e-4d6e-94f3-3cdcfde7bd1b_my.work.manager-release-1.0-jar-with-dependencies.jar:?]
    at org.apache.pulsar.shade.io.netty.util.HashedWheelTimer$Worker.run(HashedWheelTimer.java:503) [477237be-607e-4d6e-94f3-3cdcfde7bd1b_my.work.manager-release-1.0-jar-with-dependencies.jar:?]
    at org.apache.pulsar.shade.io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) [477237be-607e-4d6e-94f3-3cdcfde7bd1b_my.work.manager-release-1.0-jar-with-dependencies.jar:?]
    at java.lang.Thread.run(Thread.java:829) [?:?]
eolivelli commented 2 years ago

Do you have other libraries in the claspath ? Which client are you using? pulsar-client (shaded) or pulsar-client-original (with explicit dependencies?)

nvmav commented 2 years ago

@eolivelli This is my pulsar client library

    <dependency>
      <groupId>org.apache.pulsar</groupId>
      <artifactId>pulsar-client</artifactId>
      <version>2.10.0</version>
    </dependency>

How do I check other libraries in classpath? Is it okay if I list down all libraries in my pom.xml?

yxl1014 commented 2 years ago

If you use idea, project > external libraries > Maven: org apache. Pulsar: pulsar client: 2.10.0. Check whether the class causing the error is found. I speculate that there are other packages in Maven that cause this class not to be imported, which may be a version conflict.Because I run your code with the same configuration as you, he doesn't report an error, and my pom.xml There is only pulsar-client dependency.

github-actions[bot] commented 2 years ago

The issue had no activity for 30 days, mark with Stale label.

tisonkun commented 1 year ago

Closed as stale. Cannot reproduce and I suspect it's other issues.