C# ConsumerBuilder<;忽略,字符串>;Build()在统一中工作,但;序列不包含匹配元素“;部署到全息透镜时出错
下面的C#代码在Unity编辑器中工作得很好-它设置了卡夫卡,并按预期记录消息C# ConsumerBuilder<;忽略,字符串>;Build()在统一中工作,但;序列不包含匹配元素“;部署到全息透镜时出错,c#,unity3d,apache-kafka,hololens,C#,Unity3d,Apache Kafka,Hololens,下面的C#代码在Unity编辑器中工作得很好-它设置了卡夫卡,并按预期记录消息 using System; using System.Linq; using System.Threading; using UnityEngine; using Confluent.Kafka; public class main : MonoBehaviour { ConsumerBuilder<Ignore, string> cb; IConsumer<Ignore, str
using System;
using System.Linq;
using System.Threading;
using UnityEngine;
using Confluent.Kafka;
public class main : MonoBehaviour
{
ConsumerBuilder<Ignore, string> cb;
IConsumer<Ignore, string> c;
ConsumerConfig conf;
CancellationTokenSource cts;
int milliseconds = 10;
TimeSpan timeout;
void Start()
{
print("main start");
conf = new ConsumerConfig();
conf.GroupId = "test-consumer-group";
conf.BootstrapServers = "localhost:9092";
conf.AutoOffsetReset = AutoOffsetReset.Earliest;
cb = new ConsumerBuilder<Ignore, string>(conf);
if (cb != null)
{
print("cb is ok: " + cb.ToString());
c = cb.Build();
}
timeout = new TimeSpan(0, 0, 0, 0, milliseconds);
c.Subscribe("testTopicName");
cts = new CancellationTokenSource();
print("main started");
}
但是,在我看来,这种情况不适用于我的代码
我上传了Unity项目
以及部署到Hololens的VS构建项目(1.2 GB)
非常感谢您的任何想法或帮助 不知道我是否能帮上忙,但看到Unity3d+Kafka太好了!我猜它可能与经纪人无关?你是否有卡夫卡在全息镜头内运行(
localhost:9092
)!?我会订阅只有当消费者是正确创建的,但在您的代码中,您只是日志,如果它是空的。另一件事是,更新在每一帧都被调用,我想说的太多了,而consumer.consume()
需要时间来获取记录,我不认为设置零超时是明智之举@Paizo,好主意。1.我不确定Kafka是否可以在Hololens中运行,因为它只是一个Java服务器,但localhost可能需要更改为我的笔记本电脑的IP,我在那里运行Kafka。2.你的意思是如果(c!=null)c.Subscribe(“testTopicName”)应该运行吗?3.我发现10毫秒的超时“暂时有效”,以人的速度。c、 消费(cts)会无限期地阻塞,直到收到一条消息,这让我误以为Unity已经冻结了。不过,我确实需要对10ms进行性能测试。是的,当然,如果c为null,您将在subscribe上获得一个null指针。事实上,我甚至不认为卡夫卡在霍洛伦斯上跑步。我会将consume
与unityUpdate
或FixedUpdate
分离,您不希望冻结帧以等待记录;将记录保存在列表中,然后可以在fixedupdate中处理这些记录,例如,如果要生成网格。
Exception thrown at 0x776F3072 in MRB100.exe: Microsoft C++ exception: Il2CppExceptionWrapper at memory location 0x01F0BB84.
Exception thrown at 0x776F3072 in MRB100.exe: Microsoft C++ exception: Il2CppExceptionWrapper at memory location 0x01F0E384.
Exception thrown at 0x776F3072 in MRB100.exe: Microsoft C++ exception: Il2CppExceptionWrapper at memory location 0x01F0E384.
InvalidOperationException: Sequence contains no matching element
at System.Linq.Enumerable.Single[TSource] (System.Collections.Generic.IEnumerable`1[T] source, System.Func`2[T,TResult] predicate) [0x00000] in <00000000000000000000000000000000>:0
at Confluent.Kafka.Impl.Librdkafka.SetDelegates (System.Type nativeMethodsClass) [0x00000] in <00000000000000000000000000000000>:0
at Confluent.Kafka.Impl.Librdkafka.Initialize (System.String userSpecifiedPath) [0x00000] in <00000000000000000000000000000000>:0
at Confluent.Kafka.Consumer`2[TKey,TValue]..ctor (Confluent.Kafka.ConsumerBuilder`2[TKey,TValue] builder) [0x00000] in <00000000000000000000000000000000>:0
at Confluent.Kafka.ConsumerBuilder`2[TKey,TValue].Build () [0x00000] in <00000000000000000000000000000000>:0
at main.Start () [0x00000] in <00000000000000000000000000000000>:0
(Filename: currently not available on il2cpp Line: -1)
For example if you use
> var result = myEnumerableCollection.First(x => x.Name == person.Name);
This will throw InvalidOperationException with Sequence contains no matching element.
But if you use
> var result = myEnumerableCollection.FirstOrDefault(x => x.Name == person.Name);
> if(result == null) //did not find in the collection something went wrong or .....
Which will return you a null if its not found then you can check if the result is null and continue on with your work