UnsatisfiedLinkError向kafka发送压缩(snappy)消息时

时间:2014-01-27 10:28:25

标签: apache-kafka snappy

在我的java网络应用中,我正在向kafka发送消息。

我想在发送之前压缩我的消息,所以我在我的生产者属性中设置:

props.put(“compression.codec”,“2”);

据我所知,“2”代表snappy,但在发送消息时我得到了:

java.lang.UnsatisfiedLinkError: org.xerial.snappy.SnappyNative.maxCompressedLength(I)I
        at org.xerial.snappy.SnappyNative.maxCompressedLength(Native Method)
        at org.xerial.snappy.Snappy.maxCompressedLength(Snappy.java:316)
        at org.xerial.snappy.SnappyOutputStream.<init>(SnappyOutputStream.java:79)
        at org.xerial.snappy.SnappyOutputStream.<init>(SnappyOutputStream.java:66)
        at kafka.message.SnappyCompression.<init>(CompressionUtils.scala:61)
        at kafka.message.CompressionFactory$.apply(CompressionUtils.scala:82)
        at kafka.message.CompressionUtils$.compress(CompressionUtils.scala:109)
        at kafka.message.MessageSet$.createByteBuffer(MessageSet.scala:71)
        at kafka.message.ByteBufferMessageSet.<init>(ByteBufferMessageSet.scala:44)
        at kafka.producer.async.DefaultEventHandler$$anonfun$3.apply(DefaultEventHandler.scala:94)
        at kafka.producer.async.DefaultEventHandler$$anonfun$3.apply(DefaultEventHandler.scala:82)
        at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:233)
        at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:233)
        at scala.collection.mutable.HashMap$$anonfun$foreach$1.apply(HashMap.scala:95)
        at scala.collection.mutable.HashMap$$anonfun$foreach$1.apply(HashMap.scala:95)
        at scala.collection.Iterator$class.foreach(Iterator.scala:772)
        at scala.collection.mutable.HashTable$$anon$1.foreach(HashTable.scala:157)
        at scala.collection.mutable.HashTable$class.foreachEntry(HashTable.scala:190)
        at scala.collection.mutable.HashMap.foreachEntry(HashMap.scala:45)
        at scala.collection.mutable.HashMap.foreach(HashMap.scala:95)
        at scala.collection.TraversableLike$class.map(TraversableLike.scala:233)
        at scala.collection.mutable.HashMap.map(HashMap.scala:45)
        at kafka.producer.async.DefaultEventHandler.serialize(DefaultEventHandler.scala:82)
        at kafka.producer.async.DefaultEventHandler.handle(DefaultEventHandler.scala:44)
        at kafka.producer.async.ProducerSendThread.tryToHandle(ProducerSendThread.scala:116)
        at kafka.producer.async.ProducerSendThread$$anonfun$processEvents$3.apply(ProducerSendThread.scala:95)
        at kafka.producer.async.ProducerSendThread$$anonfun$processEvents$3.apply(ProducerSendThread.scala:71)
        at scala.collection.immutable.Stream.foreach(Stream.scala:526)
        at kafka.producer.async.ProducerSendThread.processEvents(ProducerSendThread.scala:70)
        at kafka.producer.async.ProducerSendThread.run(ProducerSendThread.scala:41)

要解决它,我尝试将snappy依赖项添加到我的pom:

    <dependency>
        <groupId>org.xerial.snappy</groupId>
        <artifactId>snappy-java</artifactId>
        <version>${snappy-version}</version>
        <scope>provided</scope>
    </dependency>

将jar添加到/ lib / ext下的jetty服务器 但仍然会收到此错误。

如果我在“compression.codec”属性中设置“0”而不是“2”,我没有像预期的那样得到异常。

为了能够使用快速压缩,我该怎么做?

这是我的snappy版本(我应该使用另一个吗?):         1.1.0.1

我正在使用在Ubuntu 12.10上运行的jetty 8.1.9部署我的应用程序。

1 个答案:

答案 0 :(得分:1)

   <dependency>
        <groupId>org.xerial.snappy</groupId>
        <artifactId>snappy-java</artifactId>
        <version>1.1.1.3</version>
    </dependency>

我遇到了同样的问题,上面的代码解决了我的问题。 jar包含适用于所有操作系统的本机库。以下是我的开发环境:

JDK version:        1.7.0_76
Kafka version:      2.10-0.8.2.1
Zookeeper version:  3.4.6