Skip to content

Commit 72175c0

Browse files
authored
start (#2)
1 parent f389580 commit 72175c0

File tree

9 files changed

+188
-2
lines changed

9 files changed

+188
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
# User-specific files (MonoDevelop/Xamarin Studio)
1313
*.userprefs
14+
**/appsettings.prod.json
1415

1516
# Build results
1617
[Dd]ebug/

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
# MySelfLogLinker
2-
Simple console app to replicate data from a production EventStore to a local instance
1+
# LinkerConsoleApp
2+
Simple .Net Core console app to replicate data from a production EventStore to a local instance. This is an example of Data Redundancy using Linker nuget package and replicate EventStore instances or clusters across different networks. Edit appsettings.json file to set origin and destination info.

src/LinkerConsoleApp.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.29209.62
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LinkerConsoleApp", "LinkerConsoleApp\LinkerConsoleApp.csproj", "{65DC6EF9-3BC9-49DE-AB2D-716F269909A8}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{65DC6EF9-3BC9-49DE-AB2D-716F269909A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{65DC6EF9-3BC9-49DE-AB2D-716F269909A8}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{65DC6EF9-3BC9-49DE-AB2D-716F269909A8}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{65DC6EF9-3BC9-49DE-AB2D-716F269909A8}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {F647AAB1-A0DC-4A82-A1D9-8257190709B5}
24+
EndGlobalSection
25+
EndGlobal
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp2.2</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="EventStore.Client" Version="5.0.2" />
10+
<PackageReference Include="Linker" Version="1.1.0" />
11+
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.2.0" />
12+
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="2.2.4" />
13+
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.2.4" />
14+
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="2.2.0" />
15+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.2.0" />
16+
<PackageReference Include="NLog" Version="4.6.7" />
17+
<PackageReference Include="NLog.Extensions.Logging" Version="1.5.4" />
18+
</ItemGroup>
19+
20+
<ItemGroup>
21+
<None Update="appsettings.json">
22+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
23+
</None>
24+
<None Update="appsettings.prod.json">
25+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
26+
</None>
27+
</ItemGroup>
28+
29+
</Project>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace LinkerConsoleApp
2+
{
3+
public class Origin
4+
{
5+
public string ConnectionString { get; set; }
6+
public string User { get; set; }
7+
public string Pass { get; set; }
8+
public string ConnectionName { get; set; }
9+
}
10+
public class Destination
11+
{
12+
public string ConnectionString { get; set; }
13+
public string User { get; set; }
14+
public string Pass { get; set; }
15+
public string ConnectionName { get; set; }
16+
}
17+
}

src/LinkerConsoleApp/NLog.config

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
4+
5+
<targets>
6+
<target name="logconsole" xsi:type="Console" />
7+
</targets>
8+
9+
<rules>
10+
<logger name="*" minlevel="Debug" writeTo="logconsole" />
11+
</rules>
12+
</nlog>

src/LinkerConsoleApp/NLogger.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System;
2+
using Linker;
3+
using NLog;
4+
5+
namespace LinkerConsoleApp
6+
{
7+
public class NLogger : ILinkerLogger
8+
{
9+
private static Logger Log = LogManager.GetCurrentClassLogger();
10+
public void Info(string message)
11+
{
12+
Log.Info(message);
13+
}
14+
15+
public void Warn(string message)
16+
{
17+
Log.Warn(message);
18+
}
19+
20+
public void Warn(string message, Exception ex)
21+
{
22+
Log.Warn($"{message}: {ex.GetBaseException().Message}");
23+
}
24+
25+
public void Error(string message)
26+
{
27+
Log.Error(message);
28+
}
29+
30+
public void Error(string message, Exception ex)
31+
{
32+
Log.Error($"{message}: {ex.GetBaseException().Message}");
33+
}
34+
35+
public void Debug(string message)
36+
{
37+
Log.Debug(message);
38+
}
39+
}
40+
}

src/LinkerConsoleApp/Program.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.IO;
4+
using EventStore.ClientAPI;
5+
using EventStore.ClientAPI.SystemData;
6+
using Linker;
7+
using Microsoft.Extensions.Configuration;
8+
using NLog;
9+
10+
namespace LinkerConsoleApp
11+
{
12+
class Program
13+
{
14+
private static Logger Log = LogManager.GetCurrentClassLogger();
15+
static void Main(string[] args)
16+
{
17+
Log.Info("Building services...");
18+
19+
var env = Environment.GetEnvironmentVariable("CORE_ENVIRONMENT");
20+
var builder = new ConfigurationBuilder()
21+
.SetBasePath(Directory.GetCurrentDirectory())
22+
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: false)
23+
.AddJsonFile($"appsettings.{env}.json", optional: true, reloadOnChange: false)
24+
.AddEnvironmentVariables();
25+
var config = builder.Build();
26+
27+
var origin = config.GetSection("origin").Get<Origin>();
28+
var destination = config.GetSection("destination").Get<Destination>();
29+
var filterService = new FilterService(new List<Filter>
30+
{
31+
new Filter { FilterOperation = FilterOperation.Exclude, FilterType = FilterType.Stream, Value = "diary-*" },
32+
new Filter { FilterOperation = FilterOperation.Include, FilterType = FilterType.Stream, Value = "*" }
33+
});
34+
35+
var service = new LinkerService(new LinkerConnectionBuilder(new Uri(origin.ConnectionString),
36+
ConnectionSettings.Create().SetDefaultUserCredentials(new UserCredentials(origin.User, origin.Pass)),
37+
origin.ConnectionName), new LinkerConnectionBuilder(new Uri(destination.ConnectionString),
38+
ConnectionSettings.Create().SetDefaultUserCredentials(new UserCredentials(destination.User, destination.Pass)),
39+
destination.ConnectionName), filterService, Settings.Default(), new NLogger());
40+
service.Start().Wait();
41+
42+
Log.Info("Replica Service started");
43+
Log.Info("Press enter to exit the program");
44+
Console.ReadLine();
45+
}
46+
}
47+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"Environment": "local",
3+
"origin": {
4+
"connectionString": "tcp://localhost:1112",
5+
"user": "admin",
6+
"pass": "changeit",
7+
"connectionName": "origin-01"
8+
},
9+
"destination": {
10+
"connectionString": "tcp://localhost:2112",
11+
"user": "admin",
12+
"pass": "changeit",
13+
"connectionName": "destination-01"
14+
}
15+
}

0 commit comments

Comments
 (0)