Kafka集成在unity3d中引发Win32Exception错误 [英] Kafka integration in unity3d throwing Win32Exception error

查看:307
本文介绍了Kafka集成在unity3d中引发Win32Exception错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在统一环境中运行 Kafka 的代码示例,因此,我创建了一个 consumer 客户端(下面提供的代码).

I am trying to run a code sample of Kafka in unity environment and for this reason, I created a consumer client (Code given below).

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Confluent.Kafka;
using Confluent.Kafka.Serialization;
using System.Text;

public class KafkaConsumer : MonoBehaviour 
{
    // Use this for initialization
    void Start () 
    {
        /*
         * The consumer application will then pick the messages from the same topic and write them to console output. 
         * The process to create the consumer application is also very simple.
         */
        var config = new Dictionary<string, object>
        {
            { "group.id","JavaInUseGroup" },
            { "bootstrap.servers", "localhost:9092" },
            { "enable.auto.commit", "false" }
        };

        using (var consumer = new Consumer<Null, string>(config, null, new StringDeserializer(Encoding.UTF8)))
        {
            consumer.Subscribe(new string[] { "javainuse-topic" });

            consumer.OnMessage += (_, msg) =>
            {
                //Console.WriteLine($"Topic: {msg.Topic} Partition: {msg.Partition} Offset :{msg.Offset} {msg.Value}");
                Debug.Log($"Topic: {msg.Topic} Partition: {msg.Partition} Offset :{msg.Offset} {msg.Value}");

                consumer.CommitAsync(msg);
            };

            while (true)
            {
                consumer.Poll(100);
            }
        }
    }
}

为了执行上述代码示例,我还添加了confluent.Kafka dll到我的项目资产文件夹中.但是每当我运行我的统一游戏时,它都会引发 error:Win32Exception :找不到指定的模块.

In order to execute the above code sample I have also added confluent.Kafka dll into my project asset folder. but whenever I run my unity game it throws an error:Win32Exception: The specified module could not be found.

作为InvalidOperationException重新抛出:加载时出错 librdkafka.dll或其从Assets/librdkafka.dll的依赖项.查看 该目录存在,如果不存在,请检查您的部署过程.你可以 还可以在调用之前自行加载库及其依赖项 到Confluent.Kafka Confluent.Kafka.Impl.LibRdKafka.Initialize (System.String userSpecifiedPath)(在 < 700d5bbe3b974ce5aed001c82b789f6a>:0)Confluent.Kafka.Consumer..ctor (System.Collections.Generic.IEnumerable 1[T] config) (at <700d5bbe3b974ce5aed001c82b789f6a>:0) Confluent.Kafka.Consumer 2 [TKey,TValue] .. ctor (System.Collections.Generic.IEnumerable 1[T] config, Confluent.Kafka.Serialization.IDeserializer 1 [T] keyDeserializer, Confluent.Kafka.Serialization.IDeserializer`1 [T] valueDeserializer) (在< 700d5bbe3b974ce5aed001c82b789f6a>:0处)KafkaConsumer.Start()(在 Assets/KafkaConsumer.cs:26)

Rethrow as InvalidOperationException: Error while loading librdkafka.dll or its dependencies from Assets/librdkafka.dll. Check the directory exists, if not check your deployment process. You can also load the library and its dependencies by yourself before any call to Confluent.Kafka Confluent.Kafka.Impl.LibRdKafka.Initialize (System.String userSpecifiedPath) (at <700d5bbe3b974ce5aed001c82b789f6a>:0) Confluent.Kafka.Consumer..ctor (System.Collections.Generic.IEnumerable1[T] config) (at <700d5bbe3b974ce5aed001c82b789f6a>:0) Confluent.Kafka.Consumer2[TKey,TValue]..ctor (System.Collections.Generic.IEnumerable1[T] config, Confluent.Kafka.Serialization.IDeserializer1[T] keyDeserializer, Confluent.Kafka.Serialization.IDeserializer`1[T] valueDeserializer) (at <700d5bbe3b974ce5aed001c82b789f6a>:0) KafkaConsumer.Start () (at Assets/KafkaConsumer.cs:26)

由于错误指出存在依赖关系问题,因此我也将这些dll复制到了asset/librdkafka/x64文件夹中

As the error states that there is dependancy problem so i have also copied these dll in assets/librdkafka/x64 folder

  1. librdkafka
  2. librdkafkacpp

  1. librdkafka
  2. librdkafkacpp

msvcr120

现在的问题是,每当我尝试播放它时,我的项目都会卡住.

Now the problem is, my project get stuck whenever i try to play it.

记住:我已经在vs 2017中通过nuget下载了所有这些dll.然后,我将这些dll统一了.

推荐答案

对于将来的用户,以下是在您的Unity3d项目中添加Kafka的过程: 实际上,有一个特定的顺序或文件夹层次结构可在您的项目中添加dll. (如果有人找到了,请与我分享,但我没有找到任何权威参考)

For future user, here is the process to add Kafka in your Unity3d Project: Actually there is a specific order or folder hierarchy to add dll in your project. (I didn't find any authoritative reference about this if someone found then please share)

  1. 首先将Confluen.Kafka dll粘贴到您的任何文件夹中

  1. 然后创建librdkafka文件夹(确保在confluent.kafka dll旁边创建了该文件夹),并将与平台相关的dll粘贴到x64或x86文件夹中
  1. Then Make librdkafka folder(Make sure it is created next to confluent.kafka dll) and paste your platform related dll in x64 or x86 Folder

现在,您可以运行我的代码示例(有问题的提及).

Now, you can run my code sample(mentioned in question).

IMP注意::构建播放器后,您必须手动将dll文件复制到Player/Managed/librdkafka文件夹中.您必须在托管文件夹中创建librdkafka文件夹,然后粘贴您的dll.(同样,我不知道为什么要这样做,但是如果有人发现了权威性的版权就可以共享)

IMP NOTE: After building the player, you have to manually copy the dll files in your Player/Managed/librdkafka folder. You have to create librdkafka folder in managed folder, then paste your dlls.(Again i don't know why it require but if someone found authoritative refrence then share)

这篇关于Kafka集成在unity3d中引发Win32Exception错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆