Skip to content

Commit

Permalink
Merge pull request #21 from Silv3rcircl3/dev
Browse files Browse the repository at this point in the history
Updated MongoDb provider to Akka 1.1.1
  • Loading branch information
alexvaluyskiy authored Aug 2, 2016
2 parents f912889 + cdacea2 commit e14d408
Show file tree
Hide file tree
Showing 30 changed files with 655 additions and 348 deletions.
55 changes: 47 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Akka.Persistence.MongoDB
# Akka.Persistence.MongoDB

Akka Persistence journal and snapshot store backed by MongoDB database.

Expand All @@ -22,22 +22,61 @@ akka.persistence.snapshot-store.mongodb.connection-string = "<database connectio
akka.persistence.snapshot-store.mongodb.collection = "<snapshot-store collection>"
```

Remember that connection string must be provided separately to Journal and Snapshot Store. To finish setup simply initialize plugin using: `MongoDbPersistence.Instance.Apply(actorSystem);`
Remember that connection string must be provided separately to Journal and Snapshot Store. To finish setup simply initialize plugin using: `MongoDbPersistence.Get(actorSystem);`

### Configuration

Both journal and snapshot store share the same configuration keys (however they resides in separate scopes, so they are definied distinctly for either journal or snapshot store):

- `class` (string with fully qualified type name) - determines class to be used as a persistent journal. Default: *Akka.Persistence.MongoDb.Journal.MongoDbJournal, Akka.Persistence.MongoDb* (for journal) and *Akka.Persistence.MongoDb.Snapshot.MongoDbSnapshotStore, Akka.Persistence.MongoDb* (for snapshot store).
- `connection-string` - connection string used to access MongoDB. Default: *mongodb://localhost/akkanet* (for journal and snapshot store).
- `collection` - collection used to store the events or snapshots. Default:
*EventJournal* (for journal) and *SnapshotStore* (for snapshot store).
```hocon
akka.persistence {
journal {
mongodb {
# qualified type name of the MongoDb persistence journal actor
class = "Akka.Persistence.MongoDb.Journal.MongoDbJournal, Akka.Persistence.MongoDb"
# connection string used for database access
connection-string = ""
# should corresponding journal table's indexes be initialized automatically
auto-initialize = off
# dispatcher used to drive journal actor
plugin-dispatcher = "akka.actor.default-dispatcher"
# MongoDb collection corresponding with persistent journal
collection = "EventJournal"
# metadata collection
metadata-collection = "Metadata"
}
}
snapshot-store {
mongodb {
# qualified type name of the MongoDB persistence snapshot actor
class = "Akka.Persistence.MongoDb.Snapshot.MongoDbSnapshotStore, Akka.Persistence.MongoDb"
# connection string used for database access
connection-string = ""
# should corresponding snapshot's indexes be initialized automatically
auto-initialize = off
# dispatcher used to drive snapshot storage actor
plugin-dispatcher = "akka.actor.default-dispatcher"
# MongoDb collection corresponding with persistent snapshot store
collection = "SnapshotStore"
}
}
}
```

### Serialization
The events and snapshots are stored as BsonDocument, so you need to register you types with the BsonClassMap before you can use your persistence actor.
Otherwise the recovery will fail and you receive a RecoveryFailure with the message:
>An error occurred while deserializing the Payload property of class \<Journal or Snapshot class>: Unknown discriminator value '\<your type>'
### Notice
- The MongoDB operator to limit the number of documents in a query only accepts an integer while akka provides a long as maximum for the loading of events during the replay. Internally the long value is cast to an integer and if the value is higher then Int32.MaxValue, Int32.MaxValue is used. So if you have stored more then 2,147,483,647 events for a singel PersistenceId, you may have a problem :wink:
- If you call SaveSnapshot in your PersistanceActor twice, without persisting any events to the journal between the first and second call, the second call will not override the exising snapshot but rather send a SaveSnapshotFailure message back. Even if storing snapshots without persisting events in the meantime make no sense at all.
- The MongoDB operator to limit the number of documents in a query only accepts an integer while akka provides a long as maximum for the loading of events during the replay. Internally the long value is cast to an integer and if the value is higher then Int32.MaxValue, Int32.MaxValue is used. So if you have stored more then 2,147,483,647 events for a single PersistenceId, you may have a problem :wink:
6 changes: 4 additions & 2 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#### 1.0.5 January 05 2016 ####
Support for Akka 1.0.5
#### 1.1.0 July 30 2016 ####
Updated to Akka.Persistence 1.1.1

#### 1.0.5 August 08 2015 ####

#### 1.0.4 August 07 2015 ####
Initial release of Akka.Persistence.MongoDb
8 changes: 8 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: '1.0.{build}'
skip_tags: true
image: Visual Studio 2015
configuration: Release
build_script:
- cmd: build.cmd Build
test_script:
- cmd: build.cmd RunTests
7 changes: 3 additions & 4 deletions build.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ pushd %~dp0

src\.nuget\NuGet.exe update -self

src\.nuget\NuGet.exe install FAKE -ConfigFile src\.nuget\Nuget.Config -OutputDirectory src\packages -ExcludeVersion -Version 4.1.0
src\.nuget\NuGet.exe install FAKE -ConfigFile src\.nuget\Nuget.Config -OutputDirectory src\packages -ExcludeVersion -Version 4.35.0

src\.nuget\NuGet.exe install xunit.runner.console -ConfigFile src\.nuget\Nuget.Config -OutputDirectory src\packages\FAKE -ExcludeVersion -Version 2.0.0
src\.nuget\NuGet.exe install nunit.runners -ConfigFile src\.nuget\Nuget.Config -OutputDirectory src\packages\FAKE -ExcludeVersion -Version 2.6.4
src\.nuget\NuGet.exe install xunit.runner.console -ConfigFile src\.nuget\Nuget.Config -OutputDirectory src\packages\FAKE -ExcludeVersion -Version 2.1.0

if not exist src\packages\SourceLink.Fake\tools\SourceLink.fsx (
src\.nuget\nuget.exe install SourceLink.Fake -ConfigFile src\.nuget\Nuget.Config -OutputDirectory src\packages -ExcludeVersion
src\.nuget\nuget.exe install SourceLink.Fake -ConfigFile src\.nuget\Nuget.Config -OutputDirectory src\packages -ExcludeVersion -Version 1.1.0
)
rem cls

Expand Down
61 changes: 14 additions & 47 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ cd __SOURCE_DIRECTORY__

let product = "Akka.NET"
let authors = [ "Akka.NET Team" ]
let copyright = "Copyright © 2013-2015 Akka.NET Team"
let copyright = "Copyright © 2013-2016 Akka.NET Team"
let company = "Akka.NET Team"
let description = "Akka.NET is a port of the popular Java/Scala framework Akka to .NET"
let tags = ["akka";"actors";"actor";"model";"Akka";"concurrency"]
Expand Down Expand Up @@ -52,7 +52,7 @@ let nugetDir = binDir @@ "nuget"
let workingDir = binDir @@ "build"
let libDir = workingDir @@ @"lib\net45\"
let nugetExe = FullName @"src\.nuget\NuGet.exe"
let slnFile = "./src/Akka.Persistence.MongoDb.sln"
let slnFile = "./src/Akka.Persistence.MongoDB.sln"

open Fake.RestorePackageHelper
Target "RestorePackages" (fun _ ->
Expand Down Expand Up @@ -103,7 +103,7 @@ Target "CopyOutput" <| fun _ ->
let src = "src" @@ project @@ @"bin/Release/"
let dst = binDir @@ project
CopyDir dst src allFiles
[ "Akka.Persistence.MongoDb"
[ "Akka.Persistence.MongoDB"
]
|> List.iter copyOutput

Expand All @@ -123,17 +123,22 @@ Target "CleanTests" <| fun _ ->
//--------------------------------------------------------------------------------
// Run tests

open XUnit2Helper
open Fake.Testing
Target "RunTests" <| fun _ ->
let xunitTestAssemblies = !! "src/**/bin/Release/*.Tests.dll"

mkdir testOutput

let xunitToolPath = findToolInSubPath "xunit.console.exe" "src/packages/xunit.runner.console*/tools"
let xunitToolPath = findToolInSubPath "xunit.console.exe" "src/packages/FAKE/xunit.runner.console*/tools"

printfn "Using XUnit runner: %s" xunitToolPath
xUnit2
(fun p -> { p with OutputDir = testOutput; ToolPath = xunitToolPath })
xunitTestAssemblies
let runSingleAssembly assembly =
let assemblyName = Path.GetFileNameWithoutExtension(assembly)
xUnit2
(fun p -> { p with XmlOutputPath = Some (testOutput + @"\" + assemblyName + "_xunit.xml"); HtmlOutputPath = Some (testOutput + @"\" + assemblyName + "_xunit.HTML"); ToolPath = xunitToolPath; TimeOut = System.TimeSpan.FromMinutes 30.0; Parallel = ParallelMode.NoParallelization })
(Seq.singleton assembly)

xunitTestAssemblies |> Seq.iter (runSingleAssembly)

//--------------------------------------------------------------------------------
// Nuget targets
Expand All @@ -153,46 +158,8 @@ module Nuget =
| _ -> release.NugetVersion

open Nuget

open NuGet.Update

//--------------------------------------------------------------------------------
// Upgrade nuget package versions for dev and production

let updateNugetPackages _ =
printfn "Updating NuGet dependencies"

let getConfigFile preRelease =
match preRelease with
| true -> "src/.nuget/NuGet.Dev.Config"
| false -> "src/.nuget/NuGet.Config"

let getPackages project =
match project with
| "Akka.Persistence.MongoDb" -> ["Akka.Persistence";]
| "Akka.Persistence.MongoDb.Tests" -> ["Akka.Persistence.TestKit";]
| _ -> []

for projectFile in !! "src/**/*.csproj" do
printfn "Updating packages for %s" projectFile
let project = Path.GetFileNameWithoutExtension projectFile
let projectDir = Path.GetDirectoryName projectFile
let config = projectDir @@ "packages.config"

NugetUpdate
(fun p ->
{ p with
ConfigFile = Some (getConfigFile isPreRelease)
Prerelease = true
ToolPath = nugetExe
RepositoryPath = "src/Packages"
Ids = getPackages project
}) config

Target "UpdateDependencies" <| fun _ ->
printfn "Invoking updateNugetPackages"
updateNugetPackages()

//--------------------------------------------------------------------------------
// Clean nuget directory

Expand Down Expand Up @@ -422,7 +389,7 @@ Target "HelpDocs" <| fun _ ->
//--------------------------------------------------------------------------------

// build dependencies
"Clean" ==> "AssemblyInfo" ==> "RestorePackages" ==> "UpdateDependencies" ==> "Build" ==> "CopyOutput" ==> "BuildRelease"
"Clean" ==> "AssemblyInfo" ==> "RestorePackages" ==> "Build" ==> "CopyOutput" ==> "BuildRelease"

// tests dependencies
"CleanTests" ==> "RunTests"
Expand Down
6 changes: 3 additions & 3 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ popd > /dev/null

mono $SCRIPT_PATH/src/.nuget/NuGet.exe update -self

mono $SCRIPT_PATH/src/.nuget/NuGet.exe install FAKE -OutputDirectory $SCRIPT_PATH/src/packages -ExcludeVersion -Version 3.28.8
mono $SCRIPT_PATH/src/.nuget/NuGet.exe install FAKE -OutputDirectory $SCRIPT_PATH/src/packages -ExcludeVersion -Version 4.35.0

mono $SCRIPT_PATH/src/.nuget/NuGet.exe install xunit.runners -OutputDirectory $SCRIPT_PATH/src/packages/FAKE -ExcludeVersion -Version 2.0.0
mono $SCRIPT_PATH/src/.nuget/NuGet.exe install xunit.runners -OutputDirectory $SCRIPT_PATH/src/packages/FAKE -ExcludeVersion -Version 2.1.0

if ! [ -e $SCRIPT_PATH/src/packages/SourceLink.Fake/tools/SourceLink.fsx ] ; then
mono $SCRIPT_PATH/src/.nuget/NuGet.exe install SourceLink.Fake -OutputDirectory $SCRIPT_PATH/src/packages -ExcludeVersion
mono $SCRIPT_PATH/src/.nuget/NuGet.exe install SourceLink.Fake -OutputDirectory $SCRIPT_PATH/src/packages -ExcludeVersion -Version 1.1.0

fi

Expand Down
3 changes: 3 additions & 0 deletions src/.nuget/NuGet.Config
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
<packageSources>
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
</packageSources>
</configuration>
6 changes: 4 additions & 2 deletions src/.nuget/NuGet.Dev.Config
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
<add key="disableSourceControlIntegration" value="true" />
</solution>
<packageSources>
<add key="NuGet official" value="https://www.nuget.org/api/v2/" /> <!-- Official package source -->
<add key="Akka.NET Nightly Build" value="https://www.myget.org/F/akkadotnet/api/v2" /> <!-- Nightly package source -->
<add key="NuGet official" value="https://www.nuget.org/api/v2/" />
<!-- Official package source -->
<add key="Akka.NET Nightly Build" value="https://www.myget.org/F/akkadotnet/api/v2" />
<!-- Nightly package source -->
</packageSources>
</configuration>
Loading

0 comments on commit e14d408

Please sign in to comment.