0

我有一个带有嵌入式 ravenDB 的简单 asp.net mvc 应用程序。

我的 global.asax.cs:

        DocumentStore = new EmbeddableDocumentStore
        {
            DataDirectory = "App_Data",
        }.Initialize();

        using (var session = DocumentStore.OpenSession())
        {
            session.Store(new ReplicationDocument
            {
                Destinations =
                {
                    new ReplicationDestination
                    {
                        Url = "http://localhost:8080",
                        Database = "TestDB"
                    }
                }
            });

            session.SaveChanges();
        }

而且我在本地使用数据库 TestDB 在 8080 端口上运行 RavenDB 服务。复制已启用。

该应用程序工作正常,除了复制。http://localhost:8080我的站点上的 TestDB (on ) 中没有文档。

如何检查复制状态?或者是否有任何文档如何设置复制?

我认为http://ravendb.net/docs/server/scaling-out/replication/from-embedded-server已经过时了。

提前致谢。

4

1 回答 1

0

以下是我在嵌入式 RavenDB 2.5 中启用它的大致步骤:

var dataStore = new EmbeddableDocumentStore
{
    DataDirectory = "mydatadir",
    UseEmbeddedHttpServer = true,
};

dataStore.Configuration.Port = 4222;

dataStore.Configuration.Settings.Add("Raven/ActiveBundles", "Replication");

dataStore.initialize()

using (var session = dataStore.OpenSession())
{
    var apiKey = new ApiKeyDefinition
    {
        Id = "Raven/ApiKeys/Replication",
        Name = "Replication",
        Secret = "MySecretAPIKey",
        Enabled = true,
        Databases = new List<DatabaseAccess>
        {
            new DatabaseAccess
            {
                TenantId = "<system>",
                Admin = true,
                ReadOnly = false
            }
        }
    };

    session.Store(apiKey);

    var nodes = new string[] { };
    var nodeSetting = "http://server1.example.com:4222, http://server2.example.com:4222";
    if (!string.IsNullOrEmpty(nodeSetting))
    {
       nodes = nodeSetting.Split(',').Select(n => n.Trim()).ToArray();
    }

    var machineName = System.Web.HttpContext.Current.Server.MachineName;
    var replication = new ReplicationDocument();

    foreach (var node in nodes)
    {
        if (node.IndexOf("://" + machineName.ToLower() + ".", StringComparison.Ordinal) < 0)
        {
            replication.Destinations.Add(new ReplicationDestination
            {
                Url = node,
                ApiKey = apiKey.FullApiKey
            });
        }
    }

    session.Store(replication);
    session.SaveChanges();
}
于 2013-12-21T20:27:08.533 回答