Replication: Using Embedded instance

Replication works using plain HTTP requests to replicate all changes from one server instance to another. When running in embedded mode, you can't replicate to that instance (since it has no HTTP endpoints), unless you use Embedded+HTTP mode but you can replicate from that instance.

Replicating from embedded instance

To replicate from embedded instance to another HTTP-enabled server instance you need to:

  • enable Replication bundle on a database e.g. you can create new database with the following code:

		new DatabaseDocument
				Id = "Northwind",
				// other configuration options omitted for simplicity
				Settings =
						{ Constants.ActiveBundles, "Replication" }
  • setup a replication by creating the ReplicationDestinations document with appropriate settings.

using (IDocumentSession session = store.OpenSession("Northwind"))
	session.Store(new ReplicationDocument
		Destinations =
				new ReplicationDestination
						Url = "http://destination-server-url:8080/", 
						Database = "destination_database_name"

Replicating to embedded instance

Replication requires HTTP endpoints on destination server to be running, yet, by default, when an embedded instance is used, internal HTTP-server is disabled. To turn it on initialize EmbeddableDocumentStore with UseEmbeddedHttpServer set to true (you can read more here).

EmbeddableDocumentStore store = new EmbeddableDocumentStore
		            UseEmbeddedHttpServer = true

Now you can replicate to an embedded instance, not just from it.