【发布时间】:2017-11-06 17:27:55
【问题描述】:
我正在尝试将 Twitter 示例流保存到 RavenDB,但遇到异常:“已达到此会话允许的最大请求数 (30)。”
This 问题也有同样的问题,但是我认为调用session.Store 我已经在按照公认的答案建议做。
我知道我做错了什么,但不确定是什么。
这是我的代码:
using Tweetinvi;
namespace TwitterNoSql
{
class Program
{
static void Main(string[] args)
{
Auth.SetUserCredentials() // redacted for SO
var stream = Stream.CreateSampleStream();
using (var session = DocumentStoreHolder.Store.OpenSession())
{
stream.TweetReceived += (sender, theTweet) =>
{
var tm = new TwitterModels
{
Id = theTweet.Tweet.Id,
TheTextFromTwitter = theTweet.Tweet.FullText
};
session.Store(tm);
session.SaveChanges();
};
stream.StartStream();
}
}
}
}
DocumentStoreHolder.cs
using System;
using Raven.Client;
using Raven.Client.Document;
namespace TwitterNoSql
{
class DocumentStoreHolder
{
private static readonly Lazy<IDocumentStore> LazyStore =
new Lazy<IDocumentStore>(() =>
{
var store = new DocumentStore
{
Url = "http://localhost:8080",
DefaultDatabase = "TwitterNoSql"
};
return store.Initialize();
});
public static IDocumentStore Store =>
LazyStore.Value;
}
}
TwitterModels.cs
namespace TwitterNoSql
{
public class TwitterModels
{
public long Id { get; set; }
public string TheTextFromTwitter { get; set; }
}
}
【问题讨论】: