RavenDB 4.1 FeaturesRunning RavenDB embedded
A fun feature we have back in RavenDB is the ability to run RavenDB as part of your own application. Zero deployment, setup or hassle.
The following is the list of steps you will need:
- Create a new project (.NET Core, .Net Framework, whatever).
- Grab the pre-release bits from MyGet.
Install-Package RavenDB.Embedded -Version 4.1.0 -Source https://www.myget.org/F/ravendb/api/v3/index.json - Ask the embedded client for a document store, and start working with documents.
And here is the code:
This is it. Your process has a dedicated RavenDB server running which will run alongside your application. When your process is done, RavenDB will shutdown and nothing is running. You don’t need to setup anything, install services or configure permissions.
For extra fun (and reliability), RavenDB is actually running as a separate process. This means that if you are debugging an application that is using an embedded RavenDB, you can stop in the debugger and open the studio, inspecting the current state of the database, running queries, etc.
You have the full capabilities of RavenDB at your disposal. This means being able to use the studio, replicate to other nodes, backup & restore, database encryption, the works. The client API used is the usual one, which means that if you need to switch from running in embedded to server mode, you only need to change your document store initialization and you are done.
We are also working now on bringing this feature to additional platforms. You’ll soon be able to write the following:
This is a Python application that is using RavenDB in embedded mode, and you’ll be able to do so across the board (Java, Node.js, Go, Ruby, etc).
More posts in "RavenDB 4.1 Features" series:
- (22 Aug 2018) MongoDB & CosmosDB Migration Wizards
- (04 Jul 2018) This document is included in your subscription
- (03 Jul 2018) Detailed query timing details
- (02 Jul 2018) Of course I know ya, dude
- (29 Jun 2018) Running RavenDB embedded
- (26 Jun 2018) Can you explain that choice?
- (20 Jun 2018) Cluster wide ACID transactions
- (19 Jun 2018) Explain that choice
- (22 May 2018) Highlighting
- (11 May 2018) Counting my counters
- (10 May 2018) JavaScript Indexes
- (04 May 2018) SQL Migration Wizard
Comments
Hi there
I love this feature as i used embedded raven before and it always "just worked". I have a little question though - will there be an option to choose where the database files will be stored? For example when i'm planning to create portable app that stores database in subdirectory of the application. I know that's not the best practise, but well.. business is business :)
How do you plan the licensing? E.g. imagine I have a microservice environment with two different containers, both using RavenDb embedded. For extra fun: Imagine the containers scale dynamically...
What a nice new!
System.IO.FileNotFoundException: Server file was not found bei Raven.Embedded.RavenServerRunner.Run(ServerOptions options) bei Raven.Embedded.EmbeddedServer.<RunServer>d__14.MoveNext()
??
Great! I've been looking forward to building a metrics analysis tool for $DAYJOB using RavenDB 4, including a Fourier Transform index...
Great news! Now if only it would allow to migrate embedded 3.5 to 4.1 including the storage format switch. That would be superb for us
This is awesome! Will it work with replications\clusters? Like if my application is running in a distributed environment, in a set of nodes.
Jakub, Yes, you can set the path of all the data files.
Christian, This is handled typically via a license bundle. You purchase N cores and use the same license in all of the containers. RavenDB is smart enough to do the distribution of the cores up to N.
We also have ISV option if you need to deploy outside your organization.
Marc, Are you using old style
csproj
?Daniel, The usual migration will work, but that takes a bit of work, I'll admin.
Yoav, Yes, it is a fully fledged embedded server. You can use that for replication, join that to a cluster, etc.
Great news! Oren, you mention ISV pricing. I can't see that on the pricing page - is it somewhere else?
Sean, That's a custom offer, you need to contact us for the full details.
No, I'm not using old style csproj.
---> System.IO.FileNotFoundException: Server file was not found
Marc, I did exactly what you did and it works, can you please make sure you are not using any cache from an older install and then try again.
Make sure your Default package management format is PackageReference and not Packages.config. Tools -> options -> Nuget Package Manager -> General
Ok. Using PackageReference seems to change things. (nugets "-Source" then can't be used anymore!) Now I get an InvalidOperationException "Unable to start server" (https://pastebin.com/wNAkqitt)
Did you reinstall everything again after changing this option? Try to start a new project make sure you clean all the files of the package from your .nuget folder, then again make sure you are using PackageReference, and try to install the package again. After you install the package and build the project can you please make sure you have the RavenDBServer folder in the build folder. If still everything is not working please write to us here https://groups.google.com/forum/#!forum/ravendb.
Deleted .nuget/*, new project, RavenDBServer was created in output directory - still the same problem. "System.InvalidOperationException: Unable to start server"
I've loaded the latest 4.1. sources from GitLab to figure out, where and how the server is started. When trying to load the server with the same arguments, I get:
"The specified framework 'Microsoft.NETCore.App', version '2.1.1' was not found."
I guess you should check if the server process was sucessfully started in RavenServerRunner or immediately failed like in this case, capturing STDOUT/STDERR.
Uninstalling and reinstalling the SDK helped (.NetCore can be a real PITA). The example is working now.
Marc, Thanks, we'll include the output of the console in the error message, yes. That is a good idea.
Interesting ... Is it really targeted to any process, or more server side ? I was considering SQLLite for storing data on end user sessions, but my data is more document oriented. What's the overhead of the database ? i.e. if I store 500Mb of data, all these data will be loaded in memory ? On end user laptop we must use as less memory as possible because we still have low level hardware. It's even more important that performance (of course up to a point). So is it a accepted use case ?
Fabrice, Yes, you can run it on server side or as part of a client application. We have quite a few customers that use us as part of Windows apps, for example. The data will NOT be loaded in memory, and we are REALLY efficient. One of our primary low end test cases is Raspberry PI, which has 1 GB of RAM, and we typically have a very small working set.
Hi,
I am getting this error, can anyone share some sample project or can help me to solve this issue. below is the stack trace.
at Raven.Embedded.EmbeddedServer.<RunServer>d__14.MoveNext() in C:\Builds\RavenDB-4.1-Nightly\src\Raven.Embedded\EmbeddedServer.cs:line 200 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Raven.Embedded.EmbeddedServer.<GetServerUriAsync>d__12.MoveNext() in C:\Builds\RavenDB-4.1-Nightly\src\Raven.Embedded\EmbeddedServer.cs:line 138 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Raven.Embedded.EmbeddedServer.<>c__DisplayClass10_0.<<GetDocumentStoreAsync>b__0>d.MoveNext() in C:\Builds\RavenDB-4.1-Nightly\src\Raven.Embedded\EmbeddedServer.cs:line 97 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Raven.Embedded.EmbeddedServer.<GetDocumentStoreAsync>d__10.MoveNext() in C:\Builds\RavenDB-4.1-Nightly\src\Raven.Embedded\EmbeddedServer.cs:line 114 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Raven.Client.Util.AsyncHelpers.RunSync[T](Func`1 task) at Raven.Embedded.EmbeddedServer.GetDocumentStore(String database) in C:\Builds\RavenDB-4.1-Nightly\src\Raven.Embedded\EmbeddedServer.cs:line 71 at ConsoleApp3.Program.Main(String[] args) in c:\users\dfn_it\source\repos\ConsoleApp3\ConsoleApp3\Program.cs:line 15
Mansoor, I would also need the actual error that was thrown, not just the stack trace.
It work for mobile app? Thinking about Xamarin.Form, all existing solution is not good as could be Raven. If not, is planned?
Mello, No, this needs the .NET Core to run. However, we'll work on something for mobile that can natively sync, yes. That is a bit further down the road, though.
Hi Ayende,
First, thank you for this magnificent Db.
How do use this feature in Windows Forms? (.net Framework FULL 4.6.1)
I try and occurs this exception: "System.IO.FileNotFoundException: 'Server file was not found'".
I created a new folder in application path, "RavenDBServer" and copied "Raven.Server.dll" to in, resolves last exception but, I tryed again and occurs a new exception: "System.InvalidOperationException: 'Unable to start the RavenDB Server Error: A fatal error was encountered. The library 'hostpolicy.dll' required to execute the application was not found in 'C:\Users*\source\repos\ConsoleApp1\ConsoleApp1\bin\Debug\RavenDBServer\'. Failed to run as a self-contained app. If this should be a framework-dependent app, add the C:\Users*\source\repos\ConsoleApp1\ConsoleApp1\bin\Debug\RavenDBServer\Raven.Server.runtimeconfig.json file specifying the appropriate framework.'"
How do resolve this? Thank you for your attention.
Samuel, You need to have the CoreCLR available to run RavenDB. This doesn't have to be installed, mind, you just need to provide the path to it in the embedded startup
Thanks. o/
Comment preview