Skip to content

Commit 017ba5a

Browse files
tried to decouple the worker from kinesis while upgrading the framework and tooling.
1 parent 3cf8f51 commit 017ba5a

24 files changed

+84
-66
lines changed

.gitignore

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## Ignore Visual Studio temporary files, build results, and
1+
## Ignore Visual Studio temporary files, build results, and
22
## files generated by popular Visual Studio add-ons.
33

44
# User-specific files
@@ -23,7 +23,8 @@ bld/
2323
[Oo]bj/
2424

2525
# Visual Studio 2015 cache/options directory
26-
.vs/
26+
.vs/
27+
.vscode/
2728
# Uncomment if you have tasks that create the project's static files in wwwroot
2829
#wwwroot/
2930

.vscode/settings.json

-3
This file was deleted.

WorkerService/KinesisNet/AsyncHelper.cs renamed to KinesisNet/AsyncHelper.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System.Threading;
33
using System.Threading.Tasks;
44

5-
namespace WorkerService.KinesisNet
5+
namespace KinesisNet
66
{
77
/// <summary>
88
/// Used to task a async task and run it without the async part.

WorkerService/KinesisNet/Consumer.cs renamed to KinesisNet/Consumer.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
using Amazon.Kinesis;
77
using Amazon.Kinesis.Model;
88
using Serilog;
9-
using WorkerService.KinesisNet.Extensions;
10-
using WorkerService.KinesisNet.Interface;
11-
using WorkerService.KinesisNet.Model;
9+
using KinesisNet.Extensions;
10+
using KinesisNet.Interface;
11+
using KinesisNet.Model;
1212

13-
namespace WorkerService.KinesisNet
13+
namespace KinesisNet
1414
{
1515
internal class Consumer : IConsumer
1616
{

WorkerService/KinesisNet/Extensions/AsyncExtensions.cs renamed to KinesisNet/Extensions/AsyncExtensions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System.Threading;
33
using System.Threading.Tasks;
44

5-
namespace WorkerService.KinesisNet.Extensions
5+
namespace KinesisNet.Extensions
66
{
77
public static class AsyncExtensions
88
{

WorkerService/KinesisNet/Interface/IConsumer.cs renamed to KinesisNet/Interface/IConsumer.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
using System.Threading.Tasks;
2-
using WorkerService.KinesisNet.Model;
2+
using KinesisNet.Interface;
3+
using KinesisNet.Model;
34

4-
namespace WorkerService.KinesisNet.Interface
5+
namespace KinesisNet.Interface
56
{
67
public interface IConsumer
78
{

WorkerService/KinesisNet/Interface/IDynamoDB.cs renamed to KinesisNet/Interface/IDynamoDB.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Threading.Tasks;
4-
using WorkerService.KinesisNet.Model;
4+
using KinesisNet.Model;
55

6-
namespace WorkerService.KinesisNet.Interface
6+
namespace KinesisNet.Interface
77
{
88
internal interface IDynamoDB
99
{

WorkerService/KinesisNet/Interface/IKManager.cs renamed to KinesisNet/Interface/IKManager.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace WorkerService.KinesisNet.Interface
1+
namespace KinesisNet.Interface
22
{
33
public interface IKManager
44
{

WorkerService/KinesisNet/Interface/IProducer.cs renamed to KinesisNet/Interface/IProducer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System.Threading.Tasks;
22
using Amazon.Kinesis.Model;
33

4-
namespace WorkerService.KinesisNet.Interface
4+
namespace KinesisNet.Interface
55
{
66
public interface IProducer
77
{

WorkerService/KinesisNet/Interface/IRecordProcessor.cs renamed to KinesisNet/Interface/IRecordProcessor.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System.Collections.Generic;
33
using Amazon.Kinesis.Model;
44

5-
namespace WorkerService.KinesisNet.Interface
5+
namespace KinesisNet.Interface
66
{
77
public interface IRecordProcessor
88
{

WorkerService/KinesisNet/Interface/IUtilities.cs renamed to KinesisNet/Interface/IUtilities.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using Amazon.Kinesis.Model;
44
using Serilog;
55

6-
namespace WorkerService.KinesisNet.Interface
6+
namespace KinesisNet.Interface
77
{
88
public interface IUtilities
99
{

WorkerService/KinesisNet/KManager.cs renamed to KinesisNet/KManager.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
using Amazon.DynamoDBv2;
44
using Amazon.Kinesis;
55
using Serilog;
6-
using WorkerService.KinesisNet.Interface;
7-
using WorkerService.KinesisNet.Persistance;
6+
using KinesisNet.Interface;
7+
using KinesisNet.Persistance;
88

9-
namespace WorkerService.KinesisNet
9+
namespace KinesisNet
1010
{
1111
public class KManager : IKManager
1212
{
@@ -73,7 +73,7 @@ public KManager(string awsKey, string awsSecret, AmazonKinesisConfig config, str
7373
{
7474
if (workerId == null)
7575
{
76-
workerId = System.Environment.MachineName;
76+
workerId = Environment.MachineName;
7777
}
7878

7979
_client = new AmazonKinesisClient(awsKey, awsSecret, awsSessionToken, config);
@@ -92,7 +92,7 @@ public KManager(IAmazonDynamoDB dynamoClient, IAmazonKinesis kinesisClient, stri
9292
Log.Debug("Entering KManager ctor");
9393
if (workerId == null)
9494
{
95-
workerId = System.Environment.MachineName;
95+
workerId = Environment.MachineName;
9696
}
9797

9898
_client = kinesisClient;
@@ -116,7 +116,7 @@ private void Init(string workerId = null)
116116
{
117117
if (workerId == null)
118118
{
119-
workerId = System.Environment.MachineName;
119+
workerId = Environment.MachineName;
120120
}
121121

122122
_utilities = new Utilities(_client, workerId);

KinesisNet/KinesisNet.csproj

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard1.6</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="AWSSDK.DynamoDBv2" Version="3.3.4.13" />
9+
<PackageReference Include="AWSSDK.Kinesis" Version="3.3.2.4" />
10+
<PackageReference Include="Serilog" Version="2.4.0" />
11+
</ItemGroup>
12+
13+
</Project>

WorkerService/KinesisNet/Model/KShard.cs renamed to KinesisNet/Model/KShard.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
using Amazon.Kinesis;
44
using Amazon.Kinesis.Model;
55

6-
namespace WorkerService.KinesisNet.Model
6+
namespace KinesisNet.Model
77
{
88
internal class KShard
99
{

WorkerService/KinesisNet/Model/RecordResponse.cs renamed to KinesisNet/Model/RecordResponse.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System.Threading;
22
using Amazon.Kinesis.Model;
33

4-
namespace WorkerService.KinesisNet.Model
4+
namespace KinesisNet.Model
55
{
66
internal class RecordResponse
77
{

WorkerService/KinesisNet/Model/Result.cs renamed to KinesisNet/Model/Result.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace WorkerService.KinesisNet.Model
1+
namespace KinesisNet.Model
22
{
33
public class Result
44
{

WorkerService/KinesisNet/Persistance/DynamoDB.cs renamed to KinesisNet/Persistance/DynamoDB.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
using Amazon.DynamoDBv2;
1010
using Amazon.DynamoDBv2.Model;
1111
using Serilog;
12-
using WorkerService.KinesisNet.Interface;
13-
using WorkerService.KinesisNet.Model;
12+
using KinesisNet.Interface;
13+
using KinesisNet.Model;
1414

15-
namespace WorkerService.KinesisNet.Persistance
15+
namespace KinesisNet.Persistance
1616
{
1717
internal class DynamoDB : IDynamoDB
1818
{

WorkerService/KinesisNet/Producer.cs renamed to KinesisNet/Producer.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
using System.Threading.Tasks;
66
using Amazon.Kinesis;
77
using Amazon.Kinesis.Model;
8-
using WorkerService.KinesisNet.Interface;
8+
using KinesisNet.Interface;
99

10-
namespace WorkerService.KinesisNet
10+
namespace KinesisNet
1111
{
1212
internal class Producer : IProducer
1313
{

WorkerService/KinesisNet/Utilities.cs renamed to KinesisNet/Utilities.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
using Amazon.Kinesis;
99
using Amazon.Kinesis.Model;
1010
using Serilog;
11-
using WorkerService.KinesisNet.Interface;
11+
using KinesisNet.Interface;
1212

13-
namespace WorkerService.KinesisNet
13+
namespace KinesisNet
1414
{
1515
internal class Utilities : IUtilities
1616
{

WebService.UnitTests/WebService.UnitTests.csproj

+4
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,8 @@
2121
<PackageReference Include="xunit" Version="2.2.0" />
2222
</ItemGroup>
2323

24+
<ItemGroup>
25+
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
26+
</ItemGroup>
27+
2428
</Project>

WorkerService/EventProcessors/RolesEventProcessor.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Text;
44
using Amazon.Kinesis.Model;
5-
using WorkerService.KinesisNet.Interface;
5+
using KinesisNet.Interface;
66

77
namespace WorkerService.EventProcessors
88
{

WorkerService/Program.cs

+12-21
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,21 @@
1-
using System;
2-
using System.Reflection;
1+
using System.Reflection;
32
using System.Threading.Tasks;
43
using Amazon;
54
using Amazon.DynamoDBv2;
65
using Amazon.Kinesis;
76
using Microsoft.Extensions.Configuration;
87
using Serilog;
9-
using Serilog.Events;
10-
using Serilog.Formatting.Json;
11-
using SeriLog.LogSanitizingFormatter;
128
using WorkerService.EventProcessors;
13-
using WorkerService.KinesisNet;
14-
using WorkerService.KinesisNet.Interface;
15-
using WorkerService.KinesisNet.Model;
16-
using WorkerService.KinesisNet.Persistance;
9+
using KinesisNet;
1710
using static System.Threading.Thread;
1811
using static System.Threading.Timeout;
19-
using static System.Console;
2012

2113
namespace WorkerService
2214
{
2315
public class Program
2416
{
25-
private static Environment _environment;
26-
private static KManager _kManager;
17+
private static Environment environment;
18+
private static KManager kManager;
2719

2820
public static void Main(string[] args)
2921
{
@@ -34,8 +26,7 @@ public static void Main(string[] args)
3426

3527
Log.Debug("Testing debug logging");
3628

37-
//new LoggerConfiguration().WriteTo.Co
38-
_environment = new Environment
29+
environment = new Environment
3930
(
4031
System.Environment.GetEnvironmentVariable("REGION"),
4132
System.Environment.GetEnvironmentVariable("DC"),
@@ -47,7 +38,7 @@ public static void Main(string[] args)
4738
.InformationalVersion
4839
);
4940

50-
Log.Information("{@Environment}", _environment);
41+
Log.Information("{@Environment}", environment);
5142

5243
Log.Information("Starting configuration");
5344

@@ -67,29 +58,29 @@ public static void Main(string[] args)
6758

6859
private static void StopListeningToEvents()
6960
{
70-
_kManager.Consumer.Stop();
61+
kManager.Consumer.Stop();
7162
}
7263

7364
public static void StartListeningForEvents()
7465
{
7566
Log.Debug("Entering StartListeningForEvents");
7667
var kinesisStreamName = "RoleStream.LIVE";
77-
var kinesisWorkerId = Assembly.GetEntryAssembly().GetName().Name + "-" + _environment.Env;
68+
var kinesisWorkerId = Assembly.GetEntryAssembly().GetName().Name + "-" + environment.Env;
7869

7970
Log.Information("KManager variables:");
8071
Log.Information($" StreamName: {kinesisStreamName}");
8172
Log.Information($" WorkerId: {kinesisWorkerId}");
8273

8374
Log.Debug("Creating Dyanmo client");
84-
var dynamoClient = new AmazonDynamoDBClient(new AmazonDynamoDBConfig{RegionEndpoint = RegionEndpoint.GetBySystemName(_environment.AwsRegion)});
75+
var dynamoClient = new AmazonDynamoDBClient(new AmazonDynamoDBConfig{RegionEndpoint = RegionEndpoint.GetBySystemName(environment.AwsRegion)});
8576
Log.Debug("Creating Kinesis client");
86-
var kinesisClient = new AmazonKinesisClient(new AmazonKinesisConfig{ RegionEndpoint = RegionEndpoint.GetBySystemName(_environment.AwsRegion )});
77+
var kinesisClient = new AmazonKinesisClient(new AmazonKinesisConfig{ RegionEndpoint = RegionEndpoint.GetBySystemName(environment.AwsRegion )});
8778

8879
Log.Debug("Starting Kmanager");
89-
_kManager = new KManager(dynamoClient, kinesisClient, kinesisStreamName, kinesisWorkerId);
80+
kManager = new KManager(dynamoClient, kinesisClient, kinesisStreamName, kinesisWorkerId);
9081

9182
Log.Debug("Starting consumer");
92-
Task.Run(() => _kManager.Consumer.Start(new RolesEventProcessor()));
83+
Task.Run(() => kManager.Consumer.Start(new RolesEventProcessor()));
9384
}
9485
}
9586
}

WorkerService/WorkerService.csproj

+12-8
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,19 @@
1111
</PropertyGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.0.2" />
15-
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="1.0.2" />
16-
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="1.0.2" />
17-
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.0.2" />
18-
<PackageReference Include="AWSSDK.DynamoDBv2" Version="3.3.2" />
19-
<PackageReference Include="AWSSDK.Kinesis" Version="3.3.1.3" />
20-
<PackageReference Include="Serilog" Version="2.4.0-dev-00767" />
21-
<PackageReference Include="Serilog.Sinks.Literate" Version="2.1.0-dev-00034" />
14+
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.1.2" />
15+
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="1.1.2" />
16+
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="1.1.2" />
17+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.2" />
18+
<PackageReference Include="AWSSDK.DynamoDBv2" Version="3.3.4.13" />
19+
<PackageReference Include="AWSSDK.Kinesis" Version="3.3.2.4" />
20+
<PackageReference Include="Serilog" Version="2.4.0" />
21+
<PackageReference Include="Serilog.Sinks.Literate" Version="2.1.0" />
2222
<PackageReference Include="SeriLog.LogSanitizingFormatter" Version="1.0.1" />
2323
</ItemGroup>
2424

25+
<ItemGroup>
26+
<ProjectReference Include="..\KinesisNet\KinesisNet.csproj" />
27+
</ItemGroup>
28+
2529
</Project>

microservice.sln

+7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{44FEDB3C-7C7E-4D87-9536-3E4B6A516073}"
77
ProjectSection(SolutionItems) = preProject
88
.editorconfig = .editorconfig
9+
.gitignore = .gitignore
910
.travis.yml = .travis.yml
1011
deploy.sh = deploy.sh
1112
docker-compose.yml = docker-compose.yml
@@ -22,6 +23,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WorkerService", "WorkerServ
2223
EndProject
2324
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WorkerService.UnitTests", "WorkerService.UnitTests\WorkerService.UnitTests.csproj", "{DF1D9DC2-C641-4D89-959B-7364F039EC1A}"
2425
EndProject
26+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "KinesisNet", "KinesisNet\KinesisNet.csproj", "{D3ADBFD7-656F-4B99-9CDB-C4DEB11E6FB9}"
27+
EndProject
2528
Global
2629
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2730
Debug|Any CPU = Debug|Any CPU
@@ -44,6 +47,10 @@ Global
4447
{DF1D9DC2-C641-4D89-959B-7364F039EC1A}.Debug|Any CPU.Build.0 = Debug|Any CPU
4548
{DF1D9DC2-C641-4D89-959B-7364F039EC1A}.Release|Any CPU.ActiveCfg = Release|Any CPU
4649
{DF1D9DC2-C641-4D89-959B-7364F039EC1A}.Release|Any CPU.Build.0 = Release|Any CPU
50+
{D3ADBFD7-656F-4B99-9CDB-C4DEB11E6FB9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
51+
{D3ADBFD7-656F-4B99-9CDB-C4DEB11E6FB9}.Debug|Any CPU.Build.0 = Debug|Any CPU
52+
{D3ADBFD7-656F-4B99-9CDB-C4DEB11E6FB9}.Release|Any CPU.ActiveCfg = Release|Any CPU
53+
{D3ADBFD7-656F-4B99-9CDB-C4DEB11E6FB9}.Release|Any CPU.Build.0 = Release|Any CPU
4754
EndGlobalSection
4855
GlobalSection(SolutionProperties) = preSolution
4956
HideSolutionNode = FALSE

0 commit comments

Comments
 (0)