Skip to content

Commit

Permalink
Routing slips
Browse files Browse the repository at this point in the history
  • Loading branch information
davidsavagejr committed Feb 4, 2015
1 parent 518d164 commit 2724ae6
Show file tree
Hide file tree
Showing 23 changed files with 264 additions and 173 deletions.
34 changes: 34 additions & 0 deletions src/ComponentAService/BuildWidgetHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Contracts;
using Models;
using NPoco;
using NServiceBus;
using NServiceBus.MessageRouting.RoutingSlips;

namespace ComponentAService
{
public class BuildWidgetHandler : IHandleMessages<BuildWidgetCommand>
{
private readonly RoutingSlip _routingSlip;

public BuildWidgetHandler(RoutingSlip routingSlip)
{
_routingSlip = routingSlip;
}

public void Handle(BuildWidgetCommand message)
{
using (var db = new Database("connstr"))
{
db.BeginTransaction();
db.Execute("UPDATE TOP(1) Component_A SET batchid = @0 WHERE batchid IS NULL", message.BatchId);
var componentA = db.Single<Component_A>("WHERE batchid = @0", message.BatchId);

_routingSlip.Attachments["componentAId"] = componentA.id.ToString();

db.CompleteTransaction();
}
}
}


}
29 changes: 19 additions & 10 deletions src/ComponentAService/ComponentAService.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ComponentAService</RootNamespace>
<AssemblyName>ComponentAService</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -32,23 +33,26 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Iesi.Collections">
<HintPath>..\packages\Iesi.Collections.4.0.1.4000\lib\net40\Iesi.Collections.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Newtonsoft.Json.6.0.5\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="NHibernate">
<HintPath>..\packages\NHibernate.4.0.1.4000\lib\net40\NHibernate.dll</HintPath>
<Reference Include="NPoco, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\NPoco.2.6.88\lib\net40\NPoco.dll</HintPath>
</Reference>
<Reference Include="NServiceBus.Core">
<HintPath>..\packages\NServiceBus.5.0.0\lib\net45\NServiceBus.Core.dll</HintPath>
</Reference>
<Reference Include="NServiceBus.Host">
<HintPath>..\packages\NServiceBus.Host.6.0.0\lib\net45\NServiceBus.Host.exe</HintPath>
</Reference>
<Reference Include="NServiceBus.NHibernate">
<HintPath>..\packages\NServiceBus.NHibernate.6.0.1\lib\net45\NServiceBus.NHibernate.dll</HintPath>
<Reference Include="NServiceBus.MessageRouting">
<HintPath>..\packages\NServiceBus.MessageRouting.1.0.1.0\lib\net451\NServiceBus.MessageRouting.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
Expand All @@ -60,6 +64,7 @@
<Compile Include="..\Service\EndpointConfig.cs">
<Link>EndpointConfig.cs</Link>
</Compile>
<Compile Include="BuildWidgetHandler.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
Expand All @@ -69,9 +74,13 @@
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\WidgetSaga\WidgetSaga.csproj">
<Project>{35b3f9b7-68bb-4280-ad50-d621f481d7da}</Project>
<Name>WidgetSaga</Name>
<ProjectReference Include="..\Contracts\Contracts.csproj">
<Project>{9B4A8CC7-D35B-4E87-8E9B-099A2E8B8F96}</Project>
<Name>Contracts</Name>
</ProjectReference>
<ProjectReference Include="..\Data\Data.csproj">
<Project>{3979870E-852C-44ED-82BF-BBED2BE17776}</Project>
<Name>Data</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
6 changes: 3 additions & 3 deletions src/ComponentAService/packages.config
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Iesi.Collections" version="4.0.1.4000" targetFramework="net45" />
<package id="NHibernate" version="4.0.1.4000" targetFramework="net45" />
<package id="Newtonsoft.Json" version="6.0.5" targetFramework="net451" />
<package id="NPoco" version="2.6.88" targetFramework="net451" />
<package id="NServiceBus" version="5.0.0" targetFramework="net45" />
<package id="NServiceBus.Host" version="6.0.0" targetFramework="net45" />
<package id="NServiceBus.NHibernate" version="6.0.1" targetFramework="net45" />
<package id="NServiceBus.MessageRouting" version="1.0.1.0" targetFramework="net451" />
</packages>
34 changes: 34 additions & 0 deletions src/ComponentBService/BuildWidgetHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Contracts;
using Models;
using NPoco;
using NServiceBus;
using NServiceBus.MessageRouting.RoutingSlips;

namespace ComponentBService
{
public class BuildWidgetHandler : IHandleMessages<BuildWidgetCommand>
{
private readonly RoutingSlip _routingSlip;

public BuildWidgetHandler(RoutingSlip routingSlip)
{
_routingSlip = routingSlip;
}

public void Handle(BuildWidgetCommand message)
{
using (var db = new Database("connstr"))
{
db.BeginTransaction();
db.Execute("UPDATE TOP(1) Component_B SET batchid = @0 WHERE batchid IS NULL", message.BatchId);
var componentB = db.Single<Component_B>("WHERE batchid = @0", message.BatchId);

_routingSlip.Attachments["componentBId"] = componentB.id.ToString();

db.CompleteTransaction();
}
}
}


}
29 changes: 19 additions & 10 deletions src/ComponentBService/ComponentBService.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ComponentBService</RootNamespace>
<AssemblyName>ComponentBService</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -32,23 +33,26 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Iesi.Collections">
<HintPath>..\packages\Iesi.Collections.4.0.1.4000\lib\net40\Iesi.Collections.dll</HintPath>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Newtonsoft.Json.6.0.5\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="NHibernate">
<HintPath>..\packages\NHibernate.4.0.1.4000\lib\net40\NHibernate.dll</HintPath>
<Reference Include="NPoco, Version=2.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\NPoco.2.6.88\lib\net40\NPoco.dll</HintPath>
</Reference>
<Reference Include="NServiceBus.Core">
<HintPath>..\packages\NServiceBus.5.1.3\lib\net45\NServiceBus.Core.dll</HintPath>
</Reference>
<Reference Include="NServiceBus.Host">
<HintPath>..\packages\NServiceBus.Host.6.0.0\lib\net45\NServiceBus.Host.exe</HintPath>
</Reference>
<Reference Include="NServiceBus.NHibernate">
<HintPath>..\packages\NServiceBus.NHibernate.6.0.1\lib\net45\NServiceBus.NHibernate.dll</HintPath>
<Reference Include="NServiceBus.MessageRouting">
<HintPath>..\packages\NServiceBus.MessageRouting.1.0.1.0\lib\net451\NServiceBus.MessageRouting.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.Composition" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
Expand All @@ -60,6 +64,7 @@
<Compile Include="..\Service\EndpointConfig.cs">
<Link>EndpointConfig.cs</Link>
</Compile>
<Compile Include="BuildWidgetHandler.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
Expand All @@ -69,9 +74,13 @@
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\WidgetSaga\WidgetSaga.csproj">
<Project>{35b3f9b7-68bb-4280-ad50-d621f481d7da}</Project>
<Name>WidgetSaga</Name>
<ProjectReference Include="..\Contracts\Contracts.csproj">
<Project>{9B4A8CC7-D35B-4E87-8E9B-099A2E8B8F96}</Project>
<Name>Contracts</Name>
</ProjectReference>
<ProjectReference Include="..\Data\Data.csproj">
<Project>{3979870E-852C-44ED-82BF-BBED2BE17776}</Project>
<Name>Data</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
6 changes: 3 additions & 3 deletions src/ComponentBService/packages.config
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Iesi.Collections" version="4.0.1.4000" targetFramework="net45" />
<package id="NHibernate" version="4.0.1.4000" targetFramework="net45" />
<package id="Newtonsoft.Json" version="6.0.5" targetFramework="net451" />
<package id="NPoco" version="2.6.88" targetFramework="net451" />
<package id="NServiceBus" version="5.1.3" targetFramework="net45" />
<package id="NServiceBus.Host" version="6.0.0" targetFramework="net45" />
<package id="NServiceBus.NHibernate" version="6.0.1" targetFramework="net45" />
<package id="NServiceBus.MessageRouting" version="1.0.1.0" targetFramework="net451" />
</packages>
4 changes: 3 additions & 1 deletion src/Contracts/Contracts.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Contracts</RootNamespace>
<AssemblyName>Contracts</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -45,6 +46,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="BuildWidgetCommand.cs" />
<Compile Include="ProcessComplete.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using NServiceBus;

namespace WidgetSaga
namespace Contracts
{
public class ProcessComplete : ICommand
{
Expand Down
6 changes: 0 additions & 6 deletions src/SampleApplication.sln
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComponentAService", "Compon
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ComponentBService", "ComponentBService\ComponentBService.csproj", "{41C8BAA5-43FD-4F2C-AF87-E426794EB140}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WidgetSaga", "WidgetSaga\WidgetSaga.csproj", "{35B3F9B7-68BB-4280-AD50-D621F481D7DA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -54,10 +52,6 @@ Global
{41C8BAA5-43FD-4F2C-AF87-E426794EB140}.Debug|Any CPU.Build.0 = Debug|Any CPU
{41C8BAA5-43FD-4F2C-AF87-E426794EB140}.Release|Any CPU.ActiveCfg = Release|Any CPU
{41C8BAA5-43FD-4F2C-AF87-E426794EB140}.Release|Any CPU.Build.0 = Release|Any CPU
{35B3F9B7-68BB-4280-AD50-D621F481D7DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{35B3F9B7-68BB-4280-AD50-D621F481D7DA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{35B3F9B7-68BB-4280-AD50-D621F481D7DA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{35B3F9B7-68BB-4280-AD50-D621F481D7DA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
22 changes: 11 additions & 11 deletions src/Service/App.config
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<configuration>
<configSections>
<section name="MessageForwardingInCaseOfFaultConfig" type="NServiceBus.Config.MessageForwardingInCaseOfFaultConfig, NServiceBus.Core" />
<section name="UnicastBusConfig" type="NServiceBus.Config.UnicastBusConfig, NServiceBus.Core" />
<section name="TransportConfig" type="NServiceBus.Config.TransportConfig, NServiceBus.Core" />
<section name="AuditConfig" type="NServiceBus.Config.AuditConfig, NServiceBus.Core" />
<section name="MessageForwardingInCaseOfFaultConfig" type="NServiceBus.Config.MessageForwardingInCaseOfFaultConfig, NServiceBus.Core"/>
<section name="UnicastBusConfig" type="NServiceBus.Config.UnicastBusConfig, NServiceBus.Core"/>
<section name="TransportConfig" type="NServiceBus.Config.TransportConfig, NServiceBus.Core"/>
<section name="AuditConfig" type="NServiceBus.Config.AuditConfig, NServiceBus.Core"/>
</configSections>
<connectionStrings>
<add name="connstr" connectionString="Server=.\SQLEXPRESS;Database=RoutingSlipsSample;Trusted_Connection=True;" providerName="System.Data.SqlClient" />
<add name="connstr" connectionString="Server=.\SQLEXPRESS;Database=RoutingSlipsSample;Trusted_Connection=True;" providerName="System.Data.SqlClient"/>
<add name="NServiceBus/Persistence" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=nservicebus;Trusted_Connection=True;"/>
</connectionStrings>
<MessageForwardingInCaseOfFaultConfig ErrorQueue="error" />
<MessageForwardingInCaseOfFaultConfig ErrorQueue="error"/>
<UnicastBusConfig>
<MessageEndpointMappings />
<MessageEndpointMappings/>
</UnicastBusConfig>
<AuditConfig QueueName="audit" />
<TransportConfig MaximumConcurrencyLevel="4" MaxRetries="2" MaximumMessageThroughputPerSecond="0" />
</configuration>
<AuditConfig QueueName="audit"/>
<TransportConfig MaximumConcurrencyLevel="4" MaxRetries="2" MaximumMessageThroughputPerSecond="0"/>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1"/></startup></configuration>
30 changes: 30 additions & 0 deletions src/Service/BuildWidgetHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.Collections.Generic;
using Contracts;
using NServiceBus;
using NServiceBus.MessageRouting.RoutingSlips;

namespace Service
{
public class BuildWidgetHandler : IHandleMessages<BuildWidgetCommand>
{
private readonly IBus _bus;

public BuildWidgetHandler(IBus bus)
{
_bus = bus;
}

public void Handle(BuildWidgetCommand message)
{
var destinations = new List<string>();
destinations.Add("ComponentAService");

if(message.NeedsComponentB)
destinations.Add("ComponentBService");

destinations.Add("WidgetService");

_bus.Route(message, destinations.ToArray());
}
}
}
5 changes: 4 additions & 1 deletion src/Service/EndpointConfig.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using NServiceBus.MessageRouting.RoutingSlips;

namespace Service
{
using NServiceBus;
Expand All @@ -6,9 +8,10 @@ public class EndpointConfig : IConfigureThisEndpoint
{
public void Customize(BusConfiguration configuration)
{
configuration.UsePersistence<NHibernatePersistence>();
configuration.UsePersistence<InMemoryPersistence>();
configuration.Transactions().DisableDistributedTransactions();
configuration.Transactions().DoNotWrapHandlersExecutionInATransactionScope();
configuration.RoutingSlips();
}
}
}
6 changes: 3 additions & 3 deletions src/Service/ProcessCompletedHandler.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using NServiceBus;
using Contracts;
using NServiceBus;
using NServiceBus.Logging;
using WidgetSaga;

namespace Service
{
class ProcessCompletedHandler : IHandleMessages<ProcessComplete>
{
static readonly ILog Logger = LogManager.GetLogger<BuildWidgetSaga>();
static readonly ILog Logger = LogManager.GetLogger<ProcessCompletedHandler>();

public void Handle(ProcessComplete message)
{
Expand Down
Loading

0 comments on commit 2724ae6

Please sign in to comment.