我正在开发一个计算连续数据流的项目。 我最近一直在讨论一些内存和网络异常,我问自己,我从数据库中获取数据的方式是否合适。
我正在使用:
以下是我如何将数据加载到actor中的示例:
public class MyActor : ReceiveActor
{
public MyActor (ImmutableRegistration registration)
{
Receives();
Self.Tell(new InitDBCache());
}
private void Receives()
{
Receive<InitDBCache>(t =>
{
var builder = new DataBaseCacheBuilder();
builder.BuildFor(registration).ContinueWith(result =>
{
return new DBCacheReceived(result.Result);
},
TaskContinuationOptions.AttachedToParent &
TaskContinuationOptions.ExecuteSynchronously).PipeTo(Self);
});
Receive<DBCacheReceived>(msg =>
{
// Init actor with retrieved data
});
}
private sealed class InitDBCache
{
public InitDBCache() { }
}
private sealed class DBCacheReceived
{
public DBCacheReceived(DataBaseCache cache)
{
this.Cache = cache;
}
public DataBaseCache Cache { get; }
}
}
DataBaseCacheBuilder是这样的:
public sealed class DataBaseCacheBuilder
{
public DataBaseCacheBuilder()
{
}
public async Task<DataBaseCache> BuildFor(ImmutableRegistration registration)
{
// I have a repository pattern on top of the ravendb client
using (var session = OutsideRefs.DataStore.OpenRavenDbSession())
{
var queryResult1 = await session.repository1.executeQueryAsync(registration.Id);
var queryResult2 = await session.repository2.executeQueryAsync(registration.Id);
return new DataBaseCache(queryResult1, queryResult2);
}
}
}
具体来说,我的计划投入了相当多的 “System.IO.IOException:无法从传输连接读取数据:远程主机强行关闭现有连接。”
ravendb客户抛出了这些例外。
是否有人发现问题或与我的代码和例外有关?
使用async / await来重新组合异步调用是不好的事情,即使我正在管道结果?