Skip to content

Commit 5fd7fd0

Browse files
committed
initial commit
1 parent fde3f50 commit 5fd7fd0

21 files changed

+626
-0
lines changed

.gitattributes

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
###############################################################################
2+
# Set default behavior to automatically normalize line endings.
3+
###############################################################################
4+
* text=auto
5+
6+
###############################################################################
7+
# Set default behavior for command prompt diff.
8+
#
9+
# This is need for earlier builds of msysgit that does not have it on by
10+
# default for csharp files.
11+
# Note: This is only used by command line
12+
###############################################################################
13+
#*.cs diff=csharp
14+
15+
###############################################################################
16+
# Set the merge driver for project and solution files
17+
#
18+
# Merging from the command prompt will add diff markers to the files if there
19+
# are conflicts (Merging from VS is not affected by the settings below, in VS
20+
# the diff markers are never inserted). Diff markers may cause the following
21+
# file extensions to fail to load in VS. An alternative would be to treat
22+
# these files as binary and thus will always conflict and require user
23+
# intervention with every merge. To do so, just uncomment the entries below
24+
###############################################################################
25+
#*.sln merge=binary
26+
#*.csproj merge=binary
27+
#*.vbproj merge=binary
28+
#*.vcxproj merge=binary
29+
#*.vcproj merge=binary
30+
#*.dbproj merge=binary
31+
#*.fsproj merge=binary
32+
#*.lsproj merge=binary
33+
#*.wixproj merge=binary
34+
#*.modelproj merge=binary
35+
#*.sqlproj merge=binary
36+
#*.wwaproj merge=binary
37+
38+
###############################################################################
39+
# behavior for image files
40+
#
41+
# image files are treated as binary by default.
42+
###############################################################################
43+
#*.jpg binary
44+
#*.png binary
45+
#*.gif binary
46+
47+
###############################################################################
48+
# diff behavior for common document formats
49+
#
50+
# Convert binary document formats to text before diffing them. This feature
51+
# is only available from the command line. Turn it on by uncommenting the
52+
# entries below.
53+
###############################################################################
54+
#*.doc diff=astextplain
55+
#*.DOC diff=astextplain
56+
#*.docx diff=astextplain
57+
#*.DOCX diff=astextplain
58+
#*.dot diff=astextplain
59+
#*.DOT diff=astextplain
60+
#*.pdf diff=astextplain
61+
#*.PDF diff=astextplain
62+
#*.rtf diff=astextplain
63+
#*.RTF diff=astextplain

.gitignore

+94
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#OS junk files
2+
[Tt]humbs.db
3+
*.DS_Store
4+
*.orig
5+
6+
#Visual Studio files
7+
*.[Oo]bj
8+
*.user
9+
*.aps
10+
*.pch
11+
*.vspscc
12+
*.vssscc
13+
*_i.c
14+
*_p.c
15+
*.ncb
16+
*.suo
17+
*.tlb
18+
*.tlh
19+
*.bak
20+
*.[Cc]ache
21+
*.ilk
22+
*.log
23+
*.lib
24+
*.sbr
25+
*.sdf
26+
*.opensdf
27+
*.unsuccessfulbuild
28+
ipch/
29+
[Oo]bj/
30+
[Bb]in
31+
Ankh.NoLoad
32+
*.vsmdi
33+
*.lock.json
34+
35+
#Tooling
36+
.idea
37+
_ReSharper*/
38+
*.resharper
39+
[Tt]est[Rr]esult*
40+
*.sass-cache
41+
42+
#Subversion files
43+
.svn
44+
45+
# Office Temp Files
46+
~$*
47+
48+
#ncrunch
49+
*ncrunch*
50+
*crunch*.local.xml
51+
52+
#Test files
53+
*.testsettings
54+
55+
#Build
56+
BuildOutput
57+
BuildOutput/*
58+
WebPublish
59+
WebPublish/*
60+
nuget
61+
nuget/*
62+
63+
#Cake
64+
tools/*
65+
!tools/packages.config
66+
**/tools/*
67+
!**/tools/packages.config
68+
69+
.vs
70+
.vscode/
71+
72+
# visual studio database projects
73+
*.dbmdl
74+
logs/*
75+
.vs/*
76+
*.project.lock.json
77+
78+
#Temp folders
79+
temp/
80+
81+
#Tools and packages
82+
.nuget
83+
.nuget/*
84+
artifacts
85+
artifacts/*
86+
packages
87+
packages/*
88+
*.lock.json
89+
90+
#NServiceBus
91+
.learningtransport/*
92+
.audit-db/*
93+
.db/*
94+
.logs/*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
Microsoft Visual Studio Solution File, Format Version 12.00
2+
# Visual Studio Version 16
3+
VisualStudioVersion = 16.0.29728.190
4+
MinimumVisualStudioVersion = 15.0.26730.12
5+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NServiceBusEndpointOne", "NServiceBusEndpointOne\NServiceBusEndpointOne.csproj", "{814CEA2E-C5F5-4315-8FC3-8517B09C5931}"
6+
EndProject
7+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EndpointsMonitor", "EndpointsMonitor\EndpointsMonitor.csproj", "{7A1C1662-35D1-4720-9F9F-4D23E9A57CE1}"
8+
EndProject
9+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlatformLauncher", "PlatformLauncher\PlatformLauncher.csproj", "{EED01887-FC83-4920-901E-2B52AFFDCBE6}"
10+
EndProject
11+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NServiceBusEndpointTwo", "NServiceBusEndpointTwo\NServiceBusEndpointTwo.csproj", "{B44D7025-D1F3-4D06-927D-AAF1DD120ED4}"
12+
EndProject
13+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Messages", "Messages\Messages.csproj", "{71C66B3D-ADD5-4B1F-9781-1631765AE8E7}"
14+
EndProject
15+
Global
16+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
17+
Debug|Any CPU = Debug|Any CPU
18+
EndGlobalSection
19+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
20+
{814CEA2E-C5F5-4315-8FC3-8517B09C5931}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21+
{814CEA2E-C5F5-4315-8FC3-8517B09C5931}.Debug|Any CPU.Build.0 = Debug|Any CPU
22+
{7A1C1662-35D1-4720-9F9F-4D23E9A57CE1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
23+
{7A1C1662-35D1-4720-9F9F-4D23E9A57CE1}.Debug|Any CPU.Build.0 = Debug|Any CPU
24+
{EED01887-FC83-4920-901E-2B52AFFDCBE6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
25+
{EED01887-FC83-4920-901E-2B52AFFDCBE6}.Debug|Any CPU.Build.0 = Debug|Any CPU
26+
{B44D7025-D1F3-4D06-927D-AAF1DD120ED4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
27+
{B44D7025-D1F3-4D06-927D-AAF1DD120ED4}.Debug|Any CPU.Build.0 = Debug|Any CPU
28+
{71C66B3D-ADD5-4B1F-9781-1631765AE8E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
29+
{71C66B3D-ADD5-4B1F-9781-1631765AE8E7}.Debug|Any CPU.Build.0 = Debug|Any CPU
30+
EndGlobalSection
31+
GlobalSection(SolutionProperties) = preSolution
32+
HideSolutionNode = FALSE
33+
EndGlobalSection
34+
GlobalSection(ExtensibilityGlobals) = postSolution
35+
SolutionGuid = {E4ACEBE4-E83E-4146-9EFF-9E61728BD574}
36+
EndGlobalSection
37+
EndGlobal
+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
using System.Threading.Tasks;
2+
using App.Metrics;
3+
using EndpointsMonitor;
4+
using NServiceBus;
5+
using NServiceBus.Logging;
6+
using ServiceControl.Contracts;
7+
8+
#region ServiceControlEventsHandlers
9+
10+
public class CustomEventsHandler :
11+
IHandleMessages<MessageFailed>,
12+
IHandleMessages<HeartbeatStopped>,
13+
IHandleMessages<HeartbeatRestored>
14+
{
15+
static ILog log = LogManager.GetLogger<CustomEventsHandler>();
16+
17+
static readonly string[] Tags =
18+
{
19+
"messagetype",
20+
"processingendpoint",
21+
"sendingendpoint"
22+
};
23+
24+
readonly IMetrics Metrics;
25+
26+
public CustomEventsHandler(IMetrics metrics)
27+
{
28+
Metrics = metrics;
29+
}
30+
31+
public Task Handle(HeartbeatRestored message, IMessageHandlerContext context)
32+
{
33+
log.Info($"Heartbeats from {message.EndpointName} have been restored.");
34+
return Task.CompletedTask;
35+
}
36+
37+
public Task Handle(HeartbeatStopped message, IMessageHandlerContext context)
38+
{
39+
log.Warn($"Heartbeats from {message.EndpointName} have stopped.");
40+
return Task.CompletedTask;
41+
}
42+
43+
public Task Handle(MessageFailed message, IMessageHandlerContext context)
44+
{
45+
log.Error($"Received ServiceControl 'MessageFailed' event for a {message.MessageType} with ID {message.FailedMessageId}.");
46+
47+
var tagValues = new[]
48+
{
49+
message.MessageType,
50+
message.ProcessingEndpoint.Name,
51+
message.SendingEndpoint.Name
52+
};
53+
54+
var tags = new MetricTags(Tags, tagValues);
55+
Metrics.Measure.Counter.Increment(NServiceBusMetricsRegistry.Counters.ErrorsPerEndpoint, tags);
56+
57+
return Task.CompletedTask;
58+
}
59+
}
60+
61+
#endregion
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<TargetFramework>netcoreapp3.1</TargetFramework>
4+
<OutputType>Exe</OutputType>
5+
<LangVersion>latest</LangVersion>
6+
</PropertyGroup>
7+
<ItemGroup>
8+
<PackageReference Include="App.Metrics.App.All" Version="4.*" />
9+
<PackageReference Include="App.Metrics.Reporting.Console" Version="4.*" />
10+
<PackageReference Include="App.Metrics.Reporting.InfluxDB" Version="4.*" />
11+
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.*" />
12+
<PackageReference Include="Newtonsoft.Json" Version="12.*" />
13+
<PackageReference Include="NServiceBus" Version="7.*" />
14+
<PackageReference Include="NServiceBus.Extensions.Hosting" Version="1.*" />
15+
<PackageReference Include="NServiceBus.Newtonsoft.Json" Version="2.*" />
16+
<PackageReference Include="NServiceBus.MSDependencyInjection" Version="0.1.4" />
17+
<PackageReference Include="ServiceControl.Contracts" Version="1.*" />
18+
</ItemGroup>
19+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
namespace EndpointsMonitor
2+
{
3+
using App.Metrics;
4+
using App.Metrics.Counter;
5+
6+
public static class NServiceBusMetricsRegistry
7+
{
8+
public static string ContextName = "NServiceBusEndpointMonitor";
9+
10+
public static class Counters
11+
{
12+
public static readonly CounterOptions ErrorsPerEndpoint = new CounterOptions
13+
{
14+
Context = ContextName,
15+
Name = "Message Failures",
16+
MeasurementUnit = Unit.Errors,
17+
ResetOnReporting = true
18+
};
19+
}
20+
}
21+
}

EndpointsMonitor/Program.cs

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using System;
2+
using System.Threading.Tasks;
3+
using App.Metrics;
4+
using App.Metrics.Formatters.Ascii;
5+
using Microsoft.Extensions.Hosting;
6+
using NServiceBus;
7+
8+
class Program
9+
{
10+
const string EndpointName = "EndpointsMonitor";
11+
12+
static async Task Main(string[] args)
13+
{
14+
Console.Title = EndpointName;
15+
16+
var host = Host
17+
.CreateDefaultBuilder(args)
18+
.ConfigureMetricsWithDefaults(builder =>
19+
{
20+
builder.OutputMetrics.AsInfluxDbLineProtocol();
21+
builder.Report.ToInfluxDb("http://127.0.0.1:8086", "nservicebus", TimeSpan.FromSeconds(1));
22+
builder.Report.ToConsole(options =>
23+
{
24+
options.FlushInterval = TimeSpan.FromSeconds(5);
25+
options.MetricsOutputFormatter = new MetricsTextOutputFormatter();
26+
});
27+
})
28+
.UseNServiceBus(context =>
29+
{
30+
var cfg = new EndpointConfiguration(EndpointName);
31+
cfg.UseSerialization<NewtonsoftSerializer>();
32+
cfg.EnableInstallers();
33+
cfg.UsePersistence<InMemoryPersistence>();
34+
cfg.SendFailedMessagesTo("error");
35+
36+
var transport = cfg.UseTransport<LearningTransport>();
37+
38+
var conventions = cfg.Conventions();
39+
conventions.DefiningEventsAs(
40+
type =>
41+
{
42+
return typeof(IEvent).IsAssignableFrom(type) ||
43+
// include ServiceControl events
44+
type.Namespace != null &&
45+
type.Namespace.StartsWith("ServiceControl.Contracts");
46+
});
47+
48+
return cfg;
49+
})
50+
.UseConsoleLifetime()
51+
.Build();
52+
53+
await host.StartAsync();
54+
55+
Console.WriteLine("Press any key to finish.");
56+
Console.ReadKey();
57+
}
58+
}

Messages/Messages.csproj

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.1</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="NServiceBus" Version="7.*" />
9+
</ItemGroup>
10+
</Project>

Messages/SimpleEventOne.cs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace NServiceBusEndpoint
2+
{
3+
using System;
4+
using NServiceBus;
5+
6+
public class SimpleEventOne : IEvent
7+
{
8+
public Guid Id { get; set; }
9+
}
10+
}

Messages/SimpleMessageOne.cs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System;
2+
using NServiceBus;
3+
4+
namespace NServiceBusEndpoint
5+
{
6+
public class SimpleMessageOne : IMessage
7+
{
8+
public Guid Id { get; set; }
9+
}
10+
}

0 commit comments

Comments
 (0)