confluent-kafka-dotnet: Kafka in Unity not working. Seems to have broken assemblies or conflicting with Unity's. How to fix?
Description
I want to integrate Kafka in Unity for a Windows build (I am on Windows).
However I either get errors such as this one:
Error: Could not load signature of Confluent.Kafka.IAsyncDeserializer`1[T]:DeserializeAsync due to: Could not load file or assembly 'System.Memory, Version=4.0.1.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' or one of its dependencies. assembly:System.Memory, Version=4.0.1.0,
Or if I install the System.Memory version that comes with the Kafka NuGet dependency, I get errors all over the place of Unity’s own method/class references no longer being found.
How to reproduce
I have tried installing the latest release (1.3.0) from nuget (using the UnityPackage ‘NuGetForUnity’). This did not seem to work and had the second type of error result described above.
I have then tried to build the source and copy the relevant DLL’s manually, and tried the same with the nuget release version. This gives the first type of error result described above.
Can anyone please help me with installing Kafka for Unity?
About this issue
- Original URL
- State: open
- Created 4 years ago
- Comments: 18 (2 by maintainers)
@ztolley I needed to do the same thing and recently figured it out. You may be missing the
librdkafka.dllfile for your system. For reference, here are the steps I used to get Kafka working in my project:.unitypackagefrom their GitHub.BootstrapServers = "localhost:9092"to reflect your server andc.Subscribe("networktopic_data");to the name of the topic you wish to subscribe to.StreamMessagewithstringfor now. ReplaceStreamMessage message = ParseStreamMessage.Decode(cr.Value);withstring message = Encoding.UTF8.GetString(cr.Value);. ReplaceProcessPBMessages.Process(message);withDebug.Log(message);. Once you can play the scene and confirm you are receiving messages in the Console, you can try using NewtonsoftJsonConvertor something similar to work for your use case.Hope that helps!
reopening, it would be good for us to test this and make this work ootb.
Hi Guys, Thank for this. I got Kafka working in Unity.
I’m using Unity 2020 with .Net 4.x
When I installed Confluent NuGet. I think most important is point 4 from the step-by-step guide.
You can see my Packages Trees. you have to put all these file there. So download the librdkafka NuGet, change the extension to .zip or open it with zip extractor and go to Runtime -> your OS Version -> native -> pick all the file and bring it to Unity
@ChulgooKim StreamMessage is just a struct I used to process / structure the sent data and was not relevant to the issue (which I fixed, see my latest comment.