向kafka发送压缩(snappy)消息时出现不满意的链接错误

l7mqbcuq  于 2021-06-07  发布在  Kafka
关注(0)|答案(1)|浏览(486)

在我的javaweb应用程序中,我向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
我正在Jetty8.1.9上部署我的应用程序,它运行在Ubuntu12.10上。

kkih6yb8

kkih6yb81#

<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

相关问题