用于visual studio bug的aws工具包?aws c#lambda无法加载Kafka的librdkafka本机库?

js5cn81o  于 2021-06-08  发布在  Kafka
关注(0)|答案(0)|浏览(408)

下面的.net core 2.1 lambda应用程序包含 Confluent.Kafka 使用aws toolkit for visual studio 2017在visual studio中创建。但是,以下代码

using (var producer = new Producer<Null, string>(config, null, new StringSerializer(Encoding.UTF8)))
{
    await producer.ProduceAsync("mytopic", null, msg);
}

在cloudwatch中出现以下错误

One or more errors occurred. (Failed to load the librdkafka native library.): AggregateException
at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
at lambda_method(Closure , Stream , Stream , LambdaContextInternal )

at Confluent.Kafka.Impl.LibRdKafka.Initialize(String userSpecifiedPath)
at Confluent.Kafka.Producer..ctor(IEnumerable`1 config, Boolean manualPoll, Boolean disableDeliveryReports)
at Confluent.Kafka.Producer`2..ctor(IEnumerable`1 config, ISerializer`1 keySerializer, ISerializer`1 valueSerializer, Boolean manualPoll, Boolean disableDeliveryReports)
at StratsLambda.Function.FunctionHandler(S3Event evnt, ILambdaContext context) in C:\work\.....

以下是aws工具包发布消息:

Executing publish command
Deleted previous publish folder
... invoking 'dotnet publish', working folder 'C:\work\....\bin\Release\netcoreapp2.1\publish'
... publish: Microsoft (R) Build Engine version 15.7.179.6572 for .NET Core
... publish: Copyright (C) Microsoft Corporation. All rights reserved.
... publish:   Restore completed in 31.3 ms for C:\work\....\StratsLambda.csproj.
... publish:   Restore completed in 62.87 ms for C:\work\....\StratsLambda.csproj.
... publish:   StratsLambda -> C:\work\....\bin\Release\netcoreapp2.1\linux-x64\StratsLambda.dll
... publish:   StratsLambda -> C:\work\....\bin\Release\netcoreapp2.1\publish\
Zipping publish folder C:\work\....\bin\Release\netcoreapp2.1\publish to C:\work\....\bin\Release\netcoreapp2.1\StratsLambda.zip
... zipping: Amazon.Lambda.Core.dll
... zipping: Amazon.Lambda.S3Events.dll
... zipping: Amazon.Lambda.Serialization.Json.dll
... zipping: AWSSDK.CloudWatchLogs.dll
... zipping: AWSSDK.Core.dll
... zipping: AWSSDK.S3.dll
... zipping: Confluent.Kafka.dll
... zipping: debian9-librdkafka.so
... zipping: librdkafka.so
... zipping: Newtonsoft.Json.dll
... zipping: Serilog.dll
... zipping: Serilog.Sinks.AwsCloudWatch.dll
... zipping: Serilog.Sinks.PeriodicBatching.dll
... zipping: StratsLambda.deps.json
... zipping: StratsLambda.dll
... zipping: StratsLambda.pdb
... zipping: StratsLambda.runtimeconfig.json
... zipping: System.Runtime.CompilerServices.Unsafe.dll
Updating code for existing function savstrats
Config settings saved to C:\work\....\aws-lambda-tools-defaults.json

我创建了一个单元测试函数来测试Kafka的生成,它可以成功地向我的Kafka发送消息。和文件夹 ...\bin\Debug\netcoreapp2.1 只有以下文件。

Name                                Length
----                                ------
StratsLambda.deps.json               58489
StratsLambda.dll                     12800
StratsLambda.pdb                      1908
StratsLambda.runtimeconfig.dev.json    238
StratsLambda.runtimeconfig.json        154

更新:stratslambda.deps.json文件包含以下部分,

"librdkafka.redist/0.11.5": {
    "native": {
      "runtimes/linux-x64/native/centos7-librdkafka.so": {
        "fileVersion": "0.0.0.0"
      },
      "runtimes/linux-x64/native/debian9-librdkafka.so": {
        "fileVersion": "0.0.0.0"
      },
      "runtimes/linux-x64/native/librdkafka.so": {
        "fileVersion": "0.0.0.0"
      }
    }
  },

我还尝试创建文件夹 runtimes/linux-x64/native 并将文件移动到zip文件中。
然而,我还是得到了错误的答案
找不到应用程序依赖项清单(myapp.deps.json)中指定的程序集:
包:“librdkafka.redist”,版本:“0.11.5”
path:'运行时/linux-x64/native/centos7 librdkafka.so'
启动请求ID:73e39d0b-8ec8-11e8-8597-。。。。版本:$最新
无法执行lambda函数。dotnet cli无法使用提供的部署包启动。请检查此lambda函数的cloudwatch日志以获取有关此失败的详细信息。:lambdaexception

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题