-
-
Notifications
You must be signed in to change notification settings - Fork 445
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
46 changed files
with
1,011 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Elasticsearch read model store | ||
|
||
Configuring EventFlow to use Elasticsearch as a store for read models is done | ||
in steps. | ||
|
||
1. Configure Elasticsearch connection in EventFlow | ||
1. Configure your Elasticsearch read models in EventFlow | ||
|
||
Given you have defined a read model class named `MyElasticsearchReadModel`, the | ||
above will look like this. | ||
|
||
```csharp | ||
var resolver = EventFlowOptions.New | ||
.ConfigureElasticsearch(new Uri("http://localhost:9200")) | ||
.UseElasticsearchReadModel<MyElasticsearchReadModel>() | ||
... | ||
.CreateResolver(); | ||
``` | ||
|
||
Overloads of `ConfigureElasticsearch(...)` is available for alternative | ||
Elasticsearch configuration. | ||
|
||
EventFlow makes assumptions regarding how you use Elasticsearch to store read | ||
models. | ||
|
||
* The host application of EventFlow is responsible for creating correct | ||
Elasticsearch type mapping for any indexes by creating index templates | ||
|
||
If you want to control the index a specific read model is stored in, create | ||
create an implementation of `IReadModelDescriptionProvider` and register it | ||
in the [EventFlow IoC](./Customize.md). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
Source/EventFlow.ReadStores.Elasticsearch.Tests/ElasticsearchTestAggregateReadModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// The MIT License (MIT) | ||
// | ||
// Copyright (c) 2015 Rasmus Mikkelsen | ||
// https://github.com/rasmus/EventFlow | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
// this software and associated documentation files (the "Software"), to deal in | ||
// the Software without restriction, including without limitation the rights to | ||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
// the Software, and to permit persons to whom the Software is furnished to do so, | ||
// subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
using EventFlow.Aggregates; | ||
using EventFlow.TestHelpers.Aggregates.Test; | ||
using EventFlow.TestHelpers.Aggregates.Test.Events; | ||
using EventFlow.TestHelpers.Aggregates.Test.ReadModels; | ||
using Nest; | ||
|
||
namespace EventFlow.ReadStores.Elasticsearch.Tests | ||
{ | ||
[ElasticType(IdProperty = "Id", Name = "test")] | ||
public class ElasticsearchTestAggregateReadModel : ITestAggregateReadModel | ||
{ | ||
[ElasticProperty( | ||
Name = "DomainErrorAfterFirstReceived", | ||
Index = FieldIndexOption.NotAnalyzed)] | ||
public bool DomainErrorAfterFirstReceived { get; set; } | ||
|
||
[ElasticProperty( | ||
Name = "PingsReceived", | ||
Index = FieldIndexOption.NotAnalyzed)] | ||
public int PingsReceived { get; set; } | ||
|
||
public void Apply(IReadModelContext context, IDomainEvent<TestAggregate, TestId, DomainErrorAfterFirstEvent> e) | ||
{ | ||
DomainErrorAfterFirstReceived = true; | ||
} | ||
|
||
public void Apply(IReadModelContext context, IDomainEvent<TestAggregate, TestId, PingEvent> e) | ||
{ | ||
PingsReceived++; | ||
} | ||
} | ||
} |
102 changes: 102 additions & 0 deletions
102
.../EventFlow.ReadStores.Elasticsearch.Tests/EventFlow.ReadStores.Elasticsearch.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{D4D7E41C-1473-4449-A128-CA4383783E6C}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>EventFlow.ReadStores.Elasticsearch.Tests</RootNamespace> | ||
<AssemblyName>EventFlow.ReadStores.Elasticsearch.Tests</AssemblyName> | ||
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<TargetFrameworkProfile /> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="Elasticsearch.Net, Version=1.0.0.0, Culture=neutral, PublicKeyToken=96c599bbe3e70f5d, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\Elasticsearch.Net.1.7.1\lib\net45\Elasticsearch.Net.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="FluentAssertions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\FluentAssertions.3.5.0\lib\net45\FluentAssertions.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="FluentAssertions.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\FluentAssertions.3.5.0\lib\net45\FluentAssertions.Core.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="Nest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=96c599bbe3e70f5d, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\NEST.1.7.1\lib\net45\Nest.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="nunit.framework, Version=2.6.4.14350, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL"> | ||
<HintPath>..\..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Net.Http" /> | ||
<Reference Include="System.Xml" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="ElasticsearchTestAggregateReadModel.cs" /> | ||
<Compile Include="Integration\ElasticsearchIntegrationTestConfiguration.cs" /> | ||
<Compile Include="Integration\ElasticsearchReadModelStoreTests.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\EventFlow.ReadStores.Elasticsearch\EventFlow.ReadStores.Elasticsearch.csproj"> | ||
<Project>{404c6099-e82f-4433-8505-5479d76660cd}</Project> | ||
<Name>EventFlow.ReadStores.Elasticsearch</Name> | ||
</ProjectReference> | ||
<ProjectReference Include="..\EventFlow.TestHelpers\EventFlow.TestHelpers.csproj"> | ||
<Project>{571d291c-5e4c-43af-855f-7c4e2f318f4c}</Project> | ||
<Name>EventFlow.TestHelpers</Name> | ||
</ProjectReference> | ||
<ProjectReference Include="..\EventFlow\EventFlow.csproj"> | ||
<Project>{11131251-778d-4d2e-bdd1-4844a789bca9}</Project> | ||
<Name>EventFlow</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="app.config" /> | ||
<None Include="packages.config" /> | ||
</ItemGroup> | ||
<ItemGroup /> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |
97 changes: 97 additions & 0 deletions
97
...w.ReadStores.Elasticsearch.Tests/Integration/ElasticsearchIntegrationTestConfiguration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// The MIT License (MIT) | ||
// | ||
// Copyright (c) 2015 Rasmus Mikkelsen | ||
// https://github.com/rasmus/EventFlow | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
// this software and associated documentation files (the "Software"), to deal in | ||
// the Software without restriction, including without limitation the rights to | ||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
// the Software, and to permit persons to whom the Software is furnished to do so, | ||
// subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
using System; | ||
using System.Net; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using EventFlow.Configuration; | ||
using EventFlow.Core; | ||
using EventFlow.ReadStores.Elasticsearch.Extensions; | ||
using EventFlow.TestHelpers; | ||
using EventFlow.TestHelpers.Aggregates.Test.ReadModels; | ||
using Nest; | ||
using NUnit.Framework; | ||
|
||
namespace EventFlow.ReadStores.Elasticsearch.Tests.Integration | ||
{ | ||
public class ElasticsearchIntegrationTestConfiguration : IntegrationTestConfiguration | ||
{ | ||
private IReadModelPopulator _readModelPopulator; | ||
private IRootResolver _resolver; | ||
private IElasticClient _elasticClient; | ||
private IReadModelDescriptionProvider _readModelDescriptionProvider; | ||
private IElasticsearchReadModelStore<ElasticsearchTestAggregateReadModel> _readModelStore; | ||
|
||
public override IRootResolver CreateRootResolver(IEventFlowOptions eventFlowOptions) | ||
{ | ||
// Disable SSL certificate validation | ||
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; | ||
|
||
var url = Environment.GetEnvironmentVariable("ELASTICSEARCH_URL"); | ||
if (string.IsNullOrEmpty(url)) | ||
{ | ||
Assert.Inconclusive("The environment variabel named 'ELASTICSEARCH_URL' isn't set. Set it to e.g. 'http://localhost:9200'"); | ||
} | ||
|
||
_resolver = eventFlowOptions | ||
.ConfigureElasticsearch(new Uri(url)) | ||
.UseElasticsearchReadModel<ElasticsearchTestAggregateReadModel>() | ||
.CreateResolver(); | ||
_elasticClient = _resolver.Resolve<IElasticClient>(); | ||
_readModelPopulator = _resolver.Resolve<IReadModelPopulator>(); | ||
_readModelDescriptionProvider = _resolver.Resolve<IReadModelDescriptionProvider>(); | ||
_readModelStore = _resolver.Resolve<IElasticsearchReadModelStore<ElasticsearchTestAggregateReadModel>>(); | ||
|
||
return _resolver; | ||
} | ||
|
||
public override async Task<ITestAggregateReadModel> GetTestAggregateReadModelAsync(IIdentity id) | ||
{ | ||
var readModelEnvelope = await _readModelStore.GetAsync(id.Value, CancellationToken.None).ConfigureAwait(false); | ||
return readModelEnvelope.ReadModel; | ||
} | ||
|
||
public override Task PurgeTestAggregateReadModelAsync() | ||
{ | ||
return _readModelPopulator.PurgeAsync<ElasticsearchTestAggregateReadModel>(CancellationToken.None); | ||
} | ||
|
||
public override Task PopulateTestAggregateReadModelAsync() | ||
{ | ||
return _readModelPopulator.PopulateAsync<ElasticsearchTestAggregateReadModel>(CancellationToken.None); | ||
} | ||
|
||
public override void TearDown() | ||
{ | ||
try | ||
{ | ||
var readModelDescription = _readModelDescriptionProvider.GetReadModelDescription<ElasticsearchTestAggregateReadModel>(); | ||
_elasticClient.DeleteIndex(readModelDescription.IndexName.Value); | ||
} | ||
catch (Exception e) | ||
{ | ||
Console.WriteLine(e.Message); | ||
} | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
.../EventFlow.ReadStores.Elasticsearch.Tests/Integration/ElasticsearchReadModelStoreTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// The MIT License (MIT) | ||
// | ||
// Copyright (c) 2015 Rasmus Mikkelsen | ||
// https://github.com/rasmus/EventFlow | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
// this software and associated documentation files (the "Software"), to deal in | ||
// the Software without restriction, including without limitation the rights to | ||
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
// the Software, and to permit persons to whom the Software is furnished to do so, | ||
// subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in all | ||
// copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
using EventFlow.TestHelpers.Suites; | ||
|
||
namespace EventFlow.ReadStores.Elasticsearch.Tests.Integration | ||
{ | ||
public class ElasticsearchReadModelStoreTests : ReadModelStoreSuite<ElasticsearchIntegrationTestConfiguration> | ||
{ | ||
} | ||
} |
Oops, something went wrong.