I am attempting to save a Twitter sample stream to RavenDB but I am encountering the exception: "The maximum number of requests (30) allowed for this session has been reached."
This question has the same problem however I think by calling session.Store
I am already doing what the accepted answer suggests.
I know I am doing something wrong but not sure what.
Here is my code:
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; }
}
}