Skip to content

Commit

Permalink
Using the Particular.PlatformSample package (#4152)
Browse files Browse the repository at this point in the history
* Make SC event subscriptions use Particular.PlatformSample

* Add netcore version of SC event subscription sample

* Add Particular.PlatformSample to custom checks V6-7 versions

* Run repoStandards.linq on new stuff

* Fix and run netcore samples listing script

* Update SC events subscription markdown and minor changes

* SC 3rd-party customchecks sample md and partials

* Final package

* JSON 12
  • Loading branch information
DavidBoike committed Dec 11, 2018
1 parent 4853f5e commit 7480ce8
Show file tree
Hide file tree
Showing 32 changed files with 239 additions and 48 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -7,6 +7,8 @@ binaries
*.lock.json
.nu
.learningtransport
.db
.logs
_UpgradeReport.*
*.cache
*~
Expand Down
1 change: 1 addition & 0 deletions samples/generated-samples-supporting-netcore.include.md
Expand Up @@ -67,6 +67,7 @@
* [Monitor Azure Storage Queues endpoints with ServiceControl adapter](/samples/servicecontrol/adapter-asq-multi-storage-account/?version=sctransportadapter_2)
* [Monitor RabbitMQ direct routing topology with ServiceControl adapter](/samples/servicecontrol/adapter-rabbitmq-different-topologies/?version=sctransportadapter_2)
* [Monitor third-party systems with custom checks](/samples/servicecontrol/monitoring3rdparty/?version=customchecks_3)
* [Monitor with ServiceControl events](/samples/servicecontrol/events-subscription/?version=servicecontrolcontracts_1)
* [Multiple Deserializers](/samples/serializers/multiple-deserializers/?version=core_7)
* [Native integration](/samples/sqltransport/native-integration/?version=sqltransport_4)
* [Native integration with RabbitMQ](/samples/rabbitmq/native-integration/?version=rabbit_5)
Expand Down
Expand Up @@ -14,19 +14,19 @@ public class CustomEventsHandler :

public Task Handle(MessageFailed message, IMessageHandlerContext context)
{
log.Error("Received ServiceControl 'MessageFailed' event for a SimpleMessage.");
log.Error($"Received ServiceControl 'MessageFailed' event for a {message.MessageType} with ID {message.FailedMessageId}.");
return Task.CompletedTask;
}

public Task Handle(HeartbeatStopped message, IMessageHandlerContext context)
{
log.Warn($"Heartbeat from {message.EndpointName} stopped.");
log.Warn($"Heartbeats from {message.EndpointName} have stopped.");
return Task.CompletedTask;
}

public Task Handle(HeartbeatRestored message, IMessageHandlerContext context)
{
log.Info($"Heartbeat from {message.EndpointName} restored.");
log.Info($"Heartbeats from {message.EndpointName} have been restored.");
return Task.CompletedTask;
}
}
Expand Down
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<OutputType>Exe</OutputType>
<LangVersion>7.1</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.*" />
<PackageReference Include="NServiceBus" Version="7.*" />
<PackageReference Include="ServiceControl.Contracts" Version="1.*" />
<PackageReference Include="NServiceBus.Newtonsoft.Json" Version="2.*" />
</ItemGroup>
</Project>
Expand Up @@ -8,7 +8,6 @@
<PackageReference Include="Newtonsoft.Json" Version="12.*" />
<PackageReference Include="NServiceBus" Version="7.*" />
<PackageReference Include="ServiceControl.Contracts" Version="1.*" />
<PackageReference Include="NServiceBus.Transport.Msmq" Version="1.*" />
<PackageReference Include="NServiceBus.Newtonsoft.Json" Version="2.*" />
</ItemGroup>
</Project>
Expand Up @@ -13,12 +13,7 @@ static async Task Main()
endpointConfiguration.UsePersistence<InMemoryPersistence>();
endpointConfiguration.SendFailedMessagesTo("error");

var transport = endpointConfiguration.UseTransport<MsmqTransport>();
var routing = transport.Routing();
routing.RegisterPublisher(
typeof(ServiceControl.Contracts.MessageFailed).Assembly,
"Particular.ServiceControl"
);
var transport = endpointConfiguration.UseTransport<LearningTransport>();

var conventions = endpointConfiguration.Conventions();
conventions.DefiningEventsAs(
Expand Down
@@ -0,0 +1,30 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26730.12
MinimumVisualStudioVersion = 15.0.26730.12
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EndpointsMonitor.Core", "EndpointsMonitor\EndpointsMonitor.Core.csproj", "{A8963C7C-F1F1-4DA9-8FCA-BE5B59CD88A1}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NServiceBusEndpoint.Core", "NServiceBusEndpoint\NServiceBusEndpoint.Core.csproj", "{72518D27-BBFF-482E-8102-7C64BA828238}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlatformLauncher.Core", "PlatformLauncher\PlatformLauncher.Core.csproj", "{A173C333-91F6-4D87-8FF6-E960B4C84450}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A8963C7C-F1F1-4DA9-8FCA-BE5B59CD88A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A8963C7C-F1F1-4DA9-8FCA-BE5B59CD88A1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{72518D27-BBFF-482E-8102-7C64BA828238}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{72518D27-BBFF-482E-8102-7C64BA828238}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A173C333-91F6-4D87-8FF6-E960B4C84450}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A173C333-91F6-4D87-8FF6-E960B4C84450}.Debug|Any CPU.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {27A88F91-DC83-4374-A818-BB89E8287243}
EndGlobalSection
EndGlobal
@@ -0,0 +1,6 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/Environment/InjectedLayers/FileInjectedLayer/=2EF370E98D1FDC4E9FD6E29F173EB613/RelativePath/@EntryValue">..\..\..\..\..\tools\Shared.DotSettings</s:String>
<s:Boolean x:Key="/Default/Environment/InjectedLayers/FileInjectedLayer/=2EF370E98D1FDC4E9FD6E29F173EB613/@KeyIndexDefined">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/InjectedLayers/InjectedLayerCustomization/=File2EF370E98D1FDC4E9FD6E29F173EB613/@KeyIndexDefined">True</s:Boolean>
<s:Double x:Key="/Default/Environment/InjectedLayers/InjectedLayerCustomization/=File2EF370E98D1FDC4E9FD6E29F173EB613/RelativePriority/@EntryValue">1</s:Double>
</wpf:ResourceDictionary>
@@ -1,2 +1,3 @@
EndpointsMonitor\EndpointsMonitor.csproj
NServiceBusEndpoint\NServiceBusEndpoint.csproj
NServiceBusEndpoint\NServiceBusEndpoint.csproj
PlatformLauncher\PlatformLauncher.csproj
@@ -1,11 +1,12 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26730.12
MinimumVisualStudioVersion = 15.0.26730.12
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NServiceBusEndpoint", "NServiceBusEndpoint\NServiceBusEndpoint.csproj", "{814CEA2E-C5F5-4315-8FC3-8517B09C5931}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NServiceBusEndpoint", "NServiceBusEndpoint\NServiceBusEndpoint.csproj", "{814CEA2E-C5F5-4315-8FC3-8517B09C5931}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EndpointsMonitor", "EndpointsMonitor\EndpointsMonitor.csproj", "{7A1C1662-35D1-4720-9F9F-4D23E9A57CE1}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EndpointsMonitor", "EndpointsMonitor\EndpointsMonitor.csproj", "{7A1C1662-35D1-4720-9F9F-4D23E9A57CE1}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlatformLauncher", "PlatformLauncher\PlatformLauncher.csproj", "{EED01887-FC83-4920-901E-2B52AFFDCBE6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -16,8 +17,13 @@ Global
{814CEA2E-C5F5-4315-8FC3-8517B09C5931}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7A1C1662-35D1-4720-9F9F-4D23E9A57CE1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7A1C1662-35D1-4720-9F9F-4D23E9A57CE1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EED01887-FC83-4920-901E-2B52AFFDCBE6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EED01887-FC83-4920-901E-2B52AFFDCBE6}.Debug|Any CPU.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E4ACEBE4-E83E-4146-9EFF-9E61728BD574}
EndGlobalSection
EndGlobal
@@ -0,0 +1,6 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:String x:Key="/Default/Environment/InjectedLayers/FileInjectedLayer/=2EF370E98D1FDC4E9FD6E29F173EB613/RelativePath/@EntryValue">..\..\..\..\..\tools\Shared.DotSettings</s:String>
<s:Boolean x:Key="/Default/Environment/InjectedLayers/FileInjectedLayer/=2EF370E98D1FDC4E9FD6E29F173EB613/@KeyIndexDefined">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/InjectedLayers/InjectedLayerCustomization/=File2EF370E98D1FDC4E9FD6E29F173EB613/@KeyIndexDefined">True</s:Boolean>
<s:Double x:Key="/Default/Environment/InjectedLayers/InjectedLayerCustomization/=File2EF370E98D1FDC4E9FD6E29F173EB613/RelativePriority/@EntryValue">1</s:Double>
</wpf:ResourceDictionary>
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<OutputType>Exe</OutputType>
<LangVersion>7.1</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.*" />
<PackageReference Include="NServiceBus" Version="7.*" />
<PackageReference Include="NServiceBus.Heartbeat" Version="3.*" />
<PackageReference Include="NServiceBus.Newtonsoft.Json" Version="2.*" />
</ItemGroup>
</Project>
Expand Up @@ -9,6 +9,5 @@
<PackageReference Include="NServiceBus" Version="7.*" />
<PackageReference Include="NServiceBus.Heartbeat" Version="3.*" />
<PackageReference Include="NServiceBus.Newtonsoft.Json" Version="2.*" />
<PackageReference Include="NServiceBus.Transport.Msmq" Version="1.*" />
</ItemGroup>
</Project>
Expand Up @@ -8,10 +8,9 @@ static async Task Main()
{
Console.Title = "NServiceBusEndpoint";
var endpointConfiguration = new EndpointConfiguration("NServiceBusEndpoint");
endpointConfiguration.UseTransport<MsmqTransport>();
endpointConfiguration.UseTransport<LearningTransport>();
endpointConfiguration.UseSerialization<NewtonsoftSerializer>();
endpointConfiguration.EnableInstallers();
endpointConfiguration.UsePersistence<InMemoryPersistence>();
endpointConfiguration.SendFailedMessagesTo("error");

#region DisableRetries
Expand Down
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<LangVersion>7.1</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Particular.PlatformSample" Version="1.0.0" />
</ItemGroup>
</Project>
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net461</TargetFramework>
<LangVersion>7.1</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Particular.PlatformSample" Version="1.0.0" />
</ItemGroup>
</Project>
@@ -0,0 +1,13 @@
namespace PlatformLauncher
{
using System;

class Program
{
static void Main(string[] args)
{
Console.Title = "PlatformLauncher";
Particular.PlatformLauncher.Launch();
}
}
}
29 changes: 18 additions & 11 deletions samples/servicecontrol/events-subscription/sample.md
Expand Up @@ -12,20 +12,21 @@ related:
- samples/servicecontrol/monitoring3rdparty
---

This sample shows how to monitor heartbeat and failed message events in ServiceControl.

## Prerequisites

1. [Install ServiceControl](/servicecontrol/installation.md).
1. Using [ServiceControl Management](/servicecontrol/license.md#servicecontrol-management-app) tool, set up ServiceControl to monitor endpoints using MSMQ transport.
1. Ensure the `ServiceControl` process is running before running the sample.
This sample shows how to monitor heartbeat and failed message events in ServiceControl, as well as observing the same activity in ServicePulse. The sample uses the [Learning Transport](/transports/learning/) and a portable version of the Particular Service Platform tools. Installing ServiceControl is **not** required.

NOTE: When using the [Azure Service Bus transport](/transports/azure-service-bus/legacy/), the subscribing endpoint must also use the same name shortening strategy as ServiceControl. See the [configuration settings](/transports/azure-service-bus/configuration.md#entity-creation), or if using the [legacy Azure Service Bus transport](), see its [sanitization strategy documentation](/transports/azure-service-bus/legacy/sanitization.md)

NOTE: The ServiceControl endpoint queue name configured in `EndpointsMonitor` must match the name of the ServiceControl instance with the underlying transport naming rules.
downloadbutton


## Running the project

Running the project will result in 3 console windows:

1. **NServiceBusEndpoint**: The endpoint that represents the system being monitored.
1. **EndpointsMonitor**: The endpoint that subscribes to ServiceControl heartbeat and failed message events.
1. **PlatformLauncher**: Runs an in-process version of ServiceControl and ServicePulse. When the ServiceControl instance is ready, a browser window will be launched displaying the ServicePulse Dashboard.

The project handles two kinds of events:

### MessageFailed event
Expand All @@ -34,9 +35,17 @@ A `MessageFailed` event is emitted when processing a message fails and the messa

To observe this in action, press <kbd>Enter</kbd> in the `NServiceBusEndpoint` console window to send a new `SimpleMessage` event. Processing of the message fails every time.

NOTE: The exception will cause the debugger to enter a breakpoint. It may be preferable to detach the debugger in order to better observe what's going on.

When a `MessageFailed` event is received, the `EndpointsMonitor` prints the following message in its console window:

> `Received ServiceControl 'MessageFailed' event for a SimpleMessage.`
```
> Received ServiceControl 'MessageFailed' event for a SimpleMessage with ID 42f25e40-a673-61f3-a505-c8dee6d16f8a
```

Using the details in the `MessageFailed` message, handler code can be written to notify operations or development staff by email or other method.

The failed message can also be viewed in the ServicePulse browser window. Navigating to the failed message allows viewing more details about the message failure.


### HeartbeatStopped and HeartbeatRestored events
Expand All @@ -56,8 +65,6 @@ Next, restart the `NServiceBusEndpoint` application and wait up to 30 seconds. W

## Code walk-through

The solution consists of two projects: `NServicebusEndpoint` and `EndpointsMonitor`. `NServiceBusEndpoint` is a simple endpoint which is monitored by the `EndpointsMonitor`.


### NServiceBusEndpoint

Expand Down
@@ -1,11 +1,12 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26730.12
MinimumVisualStudioVersion = 15.0.26730.12
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample", "Sample\Sample.csproj", "{FAA2FC1D-4554-4AA7-8D5A-334DC8AB601C}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sample", "Sample\Sample.csproj", "{FAA2FC1D-4554-4AA7-8D5A-334DC8AB601C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "3rdPartySystem", "3rdPartySystem\3rdPartySystem.csproj", "{6D5CB974-898B-4AD7-83FB-79C4477449FB}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "3rdPartySystem", "3rdPartySystem\3rdPartySystem.csproj", "{6D5CB974-898B-4AD7-83FB-79C4477449FB}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlatformLauncher", "PlatformLauncher\PlatformLauncher.csproj", "{921801B7-71AD-4BA4-A48D-7CCF4E5A9F2D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -16,8 +17,13 @@ Global
{FAA2FC1D-4554-4AA7-8D5A-334DC8AB601C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6D5CB974-898B-4AD7-83FB-79C4477449FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6D5CB974-898B-4AD7-83FB-79C4477449FB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{921801B7-71AD-4BA4-A48D-7CCF4E5A9F2D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{921801B7-71AD-4BA4-A48D-7CCF4E5A9F2D}.Debug|Any CPU.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5E01DC32-A6B7-4F67-8DA0-BE7538B3E5CC}
EndGlobalSection
EndGlobal
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net461</TargetFramework>
<LangVersion>7.1</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Particular.PlatformSample" Version="1.0.0" />
</ItemGroup>
</Project>
@@ -0,0 +1,13 @@
namespace PlatformLauncher
{
using System;

class Program
{
static void Main(string[] args)
{
Console.Title = "PlatformLauncher";
Particular.PlatformLauncher.Launch(servicePulseDefaultRoute: "/custom-checks");
}
}
}
Expand Up @@ -13,6 +13,7 @@ static async Task Main()
endpointConfiguration.UseSerialization<JsonSerializer>();
endpointConfiguration.EnableInstallers();
endpointConfiguration.UsePersistence<InMemoryPersistence>();
endpointConfiguration.UseTransport<LearningTransport>();

endpointConfiguration.ReportCustomChecksTo("Particular.ServiceControl");

Expand Down
@@ -1,11 +1,12 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26730.12
MinimumVisualStudioVersion = 15.0.26730.12
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample", "Sample\Sample.Core.csproj", "{FAA2FC1D-4554-4AA7-8D5A-334DC8AB601C}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sample.Core", "Sample\Sample.Core.csproj", "{FAA2FC1D-4554-4AA7-8D5A-334DC8AB601C}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "3rdPartySystem", "3rdPartySystem\3rdPartySystem.Core.csproj", "{6D5CB974-898B-4AD7-83FB-79C4477449FB}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "3rdPartySystem.Core", "3rdPartySystem\3rdPartySystem.Core.csproj", "{6D5CB974-898B-4AD7-83FB-79C4477449FB}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlatformLauncher.Core", "PlatformLauncher\PlatformLauncher.Core.csproj", "{D3B5AEBE-DC71-43D0-84FC-69895367F943}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -16,8 +17,13 @@ Global
{FAA2FC1D-4554-4AA7-8D5A-334DC8AB601C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6D5CB974-898B-4AD7-83FB-79C4477449FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6D5CB974-898B-4AD7-83FB-79C4477449FB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D3B5AEBE-DC71-43D0-84FC-69895367F943}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D3B5AEBE-DC71-43D0-84FC-69895367F943}.Debug|Any CPU.Build.0 = Debug|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4AD8413F-67AD-47A0-BEE2-1DE7701366B0}
EndGlobalSection
EndGlobal

0 comments on commit 7480ce8

Please sign in to comment.