From fe5a3d66c4b36a025ef1eada52107c25988b474f Mon Sep 17 00:00:00 2001 From: Alex Robson Date: Sun, 29 May 2011 19:46:47 -0400 Subject: [PATCH] Starting interfaces for conventional messaging topology --- demo/Minion/Minion.Host/Host.cs | 1 + demo/Minion/Minion.Hosted/Hosted.cs | 2 +- demo/Minion/Minion.Hosted/Initializer.cs | 13 ++- .../ConsoleApplication1.csproj | 57 ++++++++++ demo/Rabbit/ConsoleApplication1/Program.cs | 14 +++ .../Properties/AssemblyInfo.cs | 36 ++++++ demo/Rabbit/ping-pong/ping-pong.sln | 10 ++ demo/Rabbit/ping/Program.cs | 67 +++++++++++ demo/Rabbit/ping/Properties/AssemblyInfo.cs | 36 ++++++ demo/Rabbit/ping/app.config | 3 + demo/Rabbit/ping/ping.csproj | 91 +++++++++++++++ demo/Rabbit/ping/ping.sln | 54 +++++++++ demo/Rabbit/pingpong.messages/Ping.cs | 12 ++ demo/Rabbit/pingpong.messages/Pong.cs | 7 ++ .../Properties/AssemblyInfo.cs | 36 ++++++ .../pingpong.messages.csproj | 55 +++++++++ demo/Rabbit/pong/Program.cs | 58 ++++++++++ demo/Rabbit/pong/Properties/AssemblyInfo.cs | 36 ++++++ demo/Rabbit/pong/app.config | 3 + demo/Rabbit/pong/pong.csproj | 91 +++++++++++++++ src/Symbiote.Messaging/IHandle.cs | 7 +- .../Impl/IProvideMessagingConventions.cs | 18 +++ .../Symbiote.Messaging.csproj | 1 + tests/Messaging.Tests/Messaging.Tests.csproj | 14 +-- tests/Messaging.Tests/Sagas/Person.cs | 16 +++ tests/Messaging.Tests/Sagas/PersonFactory.cs | 12 ++ .../Sagas/PersonKeyAccessor.cs | 18 +++ tests/Messaging.Tests/Sagas/SetPersonName.cs | 15 +++ tests/Messaging.Tests/Sagas/TestSaga.cs | 33 ++++++ .../Sagas/when_requesting_saga.cs | 105 +----------------- .../Sagas/when_sending_command_to_saga.cs | 25 +++++ tests/Messaging.Tests/Sagas/with_bus.cs | 18 +++ tests/Messaging.Tests/with_assimilation.cs | 1 - 33 files changed, 845 insertions(+), 120 deletions(-) create mode 100644 demo/Rabbit/ConsoleApplication1/ConsoleApplication1.csproj create mode 100644 demo/Rabbit/ConsoleApplication1/Program.cs create mode 100644 demo/Rabbit/ConsoleApplication1/Properties/AssemblyInfo.cs create mode 100644 demo/Rabbit/ping/Program.cs create mode 100644 demo/Rabbit/ping/Properties/AssemblyInfo.cs create mode 100644 demo/Rabbit/ping/app.config create mode 100644 demo/Rabbit/ping/ping.csproj create mode 100644 demo/Rabbit/ping/ping.sln create mode 100644 demo/Rabbit/pingpong.messages/Ping.cs create mode 100644 demo/Rabbit/pingpong.messages/Pong.cs create mode 100644 demo/Rabbit/pingpong.messages/Properties/AssemblyInfo.cs create mode 100644 demo/Rabbit/pingpong.messages/pingpong.messages.csproj create mode 100644 demo/Rabbit/pong/Program.cs create mode 100644 demo/Rabbit/pong/Properties/AssemblyInfo.cs create mode 100644 demo/Rabbit/pong/app.config create mode 100644 demo/Rabbit/pong/pong.csproj create mode 100644 src/Symbiote.Messaging/Impl/IProvideMessagingConventions.cs create mode 100644 tests/Messaging.Tests/Sagas/Person.cs create mode 100644 tests/Messaging.Tests/Sagas/PersonFactory.cs create mode 100644 tests/Messaging.Tests/Sagas/PersonKeyAccessor.cs create mode 100644 tests/Messaging.Tests/Sagas/SetPersonName.cs create mode 100644 tests/Messaging.Tests/Sagas/TestSaga.cs create mode 100644 tests/Messaging.Tests/Sagas/when_sending_command_to_saga.cs create mode 100644 tests/Messaging.Tests/Sagas/with_bus.cs diff --git a/demo/Minion/Minion.Host/Host.cs b/demo/Minion/Minion.Host/Host.cs index 78eee141..085d1182 100644 --- a/demo/Minion/Minion.Host/Host.cs +++ b/demo/Minion/Minion.Host/Host.cs @@ -13,6 +13,7 @@ public void Start() { "Host has started." .ToInfo(); + Bus.AddLocalChannel(); Bus.AddRabbitChannel(x => x.Direct("Host").AutoDelete()); Bus.AddRabbitQueue(x => x.AutoDelete().QueueName("Host").ExchangeName("Host").StartSubscription().NoAck()); diff --git a/demo/Minion/Minion.Hosted/Hosted.cs b/demo/Minion/Minion.Hosted/Hosted.cs index ccc5f67f..9e6a0474 100644 --- a/demo/Minion/Minion.Hosted/Hosted.cs +++ b/demo/Minion/Minion.Hosted/Hosted.cs @@ -15,7 +15,7 @@ public void Start() "Hosted Daemon has been summoned!" .ToInfo(); Bus.AddLocalChannel(); - Bus.AddRabbitChannel(x => x.Direct("Host").AutoDelete()); + Bus.AddRabbitChannel(x => x.Direct("Host").AutoDelete().Durable().PersistentDelivery()); Bus.AddRabbitChannel(x => x.Direct("Hosted").AutoDelete()); Bus.AddRabbitQueue(x => x.AutoDelete().QueueName("Hosted").ExchangeName("Hosted").StartSubscription().NoAck()); diff --git a/demo/Minion/Minion.Hosted/Initializer.cs b/demo/Minion/Minion.Hosted/Initializer.cs index 4b57479f..65699cc9 100644 --- a/demo/Minion/Minion.Hosted/Initializer.cs +++ b/demo/Minion/Minion.Hosted/Initializer.cs @@ -9,12 +9,13 @@ public class Initializer : IMinion { public void Initialize() { - DaemonAssimilation.RunDaemon( Assimilate - .Initialize() - .Daemon(x => x.Arguments(new string[]{})) - .AddConsoleLogger(l => l.Info().MessageLayout(m => m.Message().Newline())) - .AddColorConsoleLogger( l => l.Info().MessageLayout( m => m.Message().Newline() ).DefineColor().Text.IsWhite().BackGround.IsRed().ForAllOutput() ) - .Rabbit(x => x.AddBroker(r => r.Defaults())) ); + Assimilate + .Initialize() + .Daemon(x => x.Arguments(new string[]{})) + .AddConsoleLogger(l => l.Info().MessageLayout(m => m.Message().Newline())) + .AddColorConsoleLogger( l => l.Info().MessageLayout( m => m.Message().Newline() ).DefineColor().Text.IsWhite().BackGround.IsRed().ForAllOutput() ) + .Rabbit(x => x.AddBroker(r => r.Defaults())) + .RunDaemon(); } } } \ No newline at end of file diff --git a/demo/Rabbit/ConsoleApplication1/ConsoleApplication1.csproj b/demo/Rabbit/ConsoleApplication1/ConsoleApplication1.csproj new file mode 100644 index 00000000..bd978054 --- /dev/null +++ b/demo/Rabbit/ConsoleApplication1/ConsoleApplication1.csproj @@ -0,0 +1,57 @@ + + + + Debug + x86 + 8.0.30703 + 2.0 + {B1DC2475-6B09-4039-A984-A1DD5385125F} + Exe + Properties + ConsoleApplication1 + ConsoleApplication1 + v4.0 + Client + 512 + + + x86 + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + x86 + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/demo/Rabbit/ConsoleApplication1/Program.cs b/demo/Rabbit/ConsoleApplication1/Program.cs new file mode 100644 index 00000000..676d164e --- /dev/null +++ b/demo/Rabbit/ConsoleApplication1/Program.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace ConsoleApplication1 +{ + class Program + { + static void Main(string[] args) + { + } + } +} diff --git a/demo/Rabbit/ConsoleApplication1/Properties/AssemblyInfo.cs b/demo/Rabbit/ConsoleApplication1/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..f9031f7b --- /dev/null +++ b/demo/Rabbit/ConsoleApplication1/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("ConsoleApplication1")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("ConsoleApplication1")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2011")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("02d7cf4c-b400-4239-821c-0b90bd8ede72")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/demo/Rabbit/ping-pong/ping-pong.sln b/demo/Rabbit/ping-pong/ping-pong.sln index fc3ff904..d64db1d1 100644 --- a/demo/Rabbit/ping-pong/ping-pong.sln +++ b/demo/Rabbit/ping-pong/ping-pong.sln @@ -6,13 +6,23 @@ EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU + Debug|Mixed Platforms = Debug|Mixed Platforms + Debug|x86 = Debug|x86 Release|Any CPU = Release|Any CPU + Release|Mixed Platforms = Release|Mixed Platforms + Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {D558BC99-6F9A-4A1A-81FA-C0C24CAC25E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {D558BC99-6F9A-4A1A-81FA-C0C24CAC25E6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D558BC99-6F9A-4A1A-81FA-C0C24CAC25E6}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {D558BC99-6F9A-4A1A-81FA-C0C24CAC25E6}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {D558BC99-6F9A-4A1A-81FA-C0C24CAC25E6}.Debug|x86.ActiveCfg = Debug|Any CPU {D558BC99-6F9A-4A1A-81FA-C0C24CAC25E6}.Release|Any CPU.ActiveCfg = Release|Any CPU {D558BC99-6F9A-4A1A-81FA-C0C24CAC25E6}.Release|Any CPU.Build.0 = Release|Any CPU + {D558BC99-6F9A-4A1A-81FA-C0C24CAC25E6}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {D558BC99-6F9A-4A1A-81FA-C0C24CAC25E6}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {D558BC99-6F9A-4A1A-81FA-C0C24CAC25E6}.Release|x86.ActiveCfg = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/demo/Rabbit/ping/Program.cs b/demo/Rabbit/ping/Program.cs new file mode 100644 index 00000000..902e4a45 --- /dev/null +++ b/demo/Rabbit/ping/Program.cs @@ -0,0 +1,67 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using pingpong.messages; +using Symbiote.Core; +using Symbiote.Core.Extensions; +using Symbiote.Daemon; +using Symbiote.Messaging; +using Symbiote.Rabbit; +using Symbiote.Log4Net; + +namespace ping +{ + class Program + { + static void Main(string[] args) + { + Assimilate + .Initialize() + .Rabbit( x => x.AddBroker( b => b.Defaults() ) ) + .AddConsoleLogger( x => x.Debug().MessageLayout( m => m.Message().Newline() ) ) + .Daemon( x => x.Name( "ping" ) ) + .RunDaemon(); + } + } + + public class PingService : IDaemon + { + public IBus Bus { get; set; } + + public void Start() + { + Bus.AddRabbitChannel( x => x.Direct( "ping" ) ); + Bus.AddRabbitQueue( x => x.ExchangeName( "ping" ).QueueName( "ping" ).NoAck() ); + + + Enumerable.Range( 0, 100 ).ForEach( x => + { + Bus.Request( "ping", new Ping() ).OnValue( p => + "Received pong!".ToInfo() + ); + Thread.Sleep( 1000 ); + } ); + } + + public void Stop() + { + + } + + public PingService( IBus bus ) + { + Bus = bus; + } + } + + public class PongHandler : IHandle + { + public Action Handle( Pong message ) + { + "Received Pong!".ToInfo(); + return x => x.Acknowledge(); + } + } +} diff --git a/demo/Rabbit/ping/Properties/AssemblyInfo.cs b/demo/Rabbit/ping/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..71a56701 --- /dev/null +++ b/demo/Rabbit/ping/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("ping")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("ping")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2011")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("08a6524b-412d-4e0e-970c-cc01dc7e58a8")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/demo/Rabbit/ping/app.config b/demo/Rabbit/ping/app.config new file mode 100644 index 00000000..e3656033 --- /dev/null +++ b/demo/Rabbit/ping/app.config @@ -0,0 +1,3 @@ + + + diff --git a/demo/Rabbit/ping/ping.csproj b/demo/Rabbit/ping/ping.csproj new file mode 100644 index 00000000..57515b22 --- /dev/null +++ b/demo/Rabbit/ping/ping.csproj @@ -0,0 +1,91 @@ + + + + Debug + x86 + 8.0.30703 + 2.0 + {F346B1C1-3007-4659-A292-BEAE0DC2601D} + Exe + Properties + ping + ping + v4.0 + + + 512 + + + x86 + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + x86 + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\..\..\bin\debug\CommandLine.dll + + + ..\..\..\bin\debug\log4net.dll + + + ..\..\..\bin\debug\RabbitMQ.Client.dll + + + ..\..\..\bin\debug\Symbiote.Core.dll + + + ..\..\..\bin\debug\Symbiote.Daemon.dll + + + ..\..\..\bin\debug\Symbiote.Log4Net.dll + + + ..\..\..\bin\debug\Symbiote.Messaging.dll + + + ..\..\..\bin\debug\Symbiote.Rabbit.dll + + + + + + + + + + + + + + + + + + + {EA3F4A1C-3248-4C71-A9F4-7CFF3ABF778A} + pingpong.messages + + + + + \ No newline at end of file diff --git a/demo/Rabbit/ping/ping.sln b/demo/Rabbit/ping/ping.sln new file mode 100644 index 00000000..02ddd23b --- /dev/null +++ b/demo/Rabbit/ping/ping.sln @@ -0,0 +1,54 @@ + +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ping", "ping.csproj", "{F346B1C1-3007-4659-A292-BEAE0DC2601D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "pong", "..\pong\pong.csproj", "{E474F71A-CB4B-42DA-89F3-4D242E847275}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "pingpong.messages", "..\pingpong.messages\pingpong.messages.csproj", "{EA3F4A1C-3248-4C71-A9F4-7CFF3ABF778A}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|Mixed Platforms = Debug|Mixed Platforms + Debug|x86 = Debug|x86 + Release|Any CPU = Release|Any CPU + Release|Mixed Platforms = Release|Mixed Platforms + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {F346B1C1-3007-4659-A292-BEAE0DC2601D}.Debug|Any CPU.ActiveCfg = Debug|x86 + {F346B1C1-3007-4659-A292-BEAE0DC2601D}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {F346B1C1-3007-4659-A292-BEAE0DC2601D}.Debug|Mixed Platforms.Build.0 = Debug|x86 + {F346B1C1-3007-4659-A292-BEAE0DC2601D}.Debug|x86.ActiveCfg = Debug|x86 + {F346B1C1-3007-4659-A292-BEAE0DC2601D}.Debug|x86.Build.0 = Debug|x86 + {F346B1C1-3007-4659-A292-BEAE0DC2601D}.Release|Any CPU.ActiveCfg = Release|x86 + {F346B1C1-3007-4659-A292-BEAE0DC2601D}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {F346B1C1-3007-4659-A292-BEAE0DC2601D}.Release|Mixed Platforms.Build.0 = Release|x86 + {F346B1C1-3007-4659-A292-BEAE0DC2601D}.Release|x86.ActiveCfg = Release|x86 + {F346B1C1-3007-4659-A292-BEAE0DC2601D}.Release|x86.Build.0 = Release|x86 + {E474F71A-CB4B-42DA-89F3-4D242E847275}.Debug|Any CPU.ActiveCfg = Debug|x86 + {E474F71A-CB4B-42DA-89F3-4D242E847275}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 + {E474F71A-CB4B-42DA-89F3-4D242E847275}.Debug|Mixed Platforms.Build.0 = Debug|x86 + {E474F71A-CB4B-42DA-89F3-4D242E847275}.Debug|x86.ActiveCfg = Debug|x86 + {E474F71A-CB4B-42DA-89F3-4D242E847275}.Debug|x86.Build.0 = Debug|x86 + {E474F71A-CB4B-42DA-89F3-4D242E847275}.Release|Any CPU.ActiveCfg = Release|x86 + {E474F71A-CB4B-42DA-89F3-4D242E847275}.Release|Mixed Platforms.ActiveCfg = Release|x86 + {E474F71A-CB4B-42DA-89F3-4D242E847275}.Release|Mixed Platforms.Build.0 = Release|x86 + {E474F71A-CB4B-42DA-89F3-4D242E847275}.Release|x86.ActiveCfg = Release|x86 + {E474F71A-CB4B-42DA-89F3-4D242E847275}.Release|x86.Build.0 = Release|x86 + {EA3F4A1C-3248-4C71-A9F4-7CFF3ABF778A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EA3F4A1C-3248-4C71-A9F4-7CFF3ABF778A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EA3F4A1C-3248-4C71-A9F4-7CFF3ABF778A}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {EA3F4A1C-3248-4C71-A9F4-7CFF3ABF778A}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {EA3F4A1C-3248-4C71-A9F4-7CFF3ABF778A}.Debug|x86.ActiveCfg = Debug|Any CPU + {EA3F4A1C-3248-4C71-A9F4-7CFF3ABF778A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EA3F4A1C-3248-4C71-A9F4-7CFF3ABF778A}.Release|Any CPU.Build.0 = Release|Any CPU + {EA3F4A1C-3248-4C71-A9F4-7CFF3ABF778A}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {EA3F4A1C-3248-4C71-A9F4-7CFF3ABF778A}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {EA3F4A1C-3248-4C71-A9F4-7CFF3ABF778A}.Release|x86.ActiveCfg = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/demo/Rabbit/pingpong.messages/Ping.cs b/demo/Rabbit/pingpong.messages/Ping.cs new file mode 100644 index 00000000..474dfb68 --- /dev/null +++ b/demo/Rabbit/pingpong.messages/Ping.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace pingpong.messages +{ + public class Ping + { + public string Message { get; set; } + } +} diff --git a/demo/Rabbit/pingpong.messages/Pong.cs b/demo/Rabbit/pingpong.messages/Pong.cs new file mode 100644 index 00000000..acb3101e --- /dev/null +++ b/demo/Rabbit/pingpong.messages/Pong.cs @@ -0,0 +1,7 @@ +namespace pingpong.messages +{ + public class Pong + { + public string Message { get; set; } + } +} \ No newline at end of file diff --git a/demo/Rabbit/pingpong.messages/Properties/AssemblyInfo.cs b/demo/Rabbit/pingpong.messages/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..df48f7db --- /dev/null +++ b/demo/Rabbit/pingpong.messages/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("pingpong.messages")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("pingpong.messages")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2011")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("6fb35bc7-d8b4-4988-8d79-f0e4fa2108d2")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/demo/Rabbit/pingpong.messages/pingpong.messages.csproj b/demo/Rabbit/pingpong.messages/pingpong.messages.csproj new file mode 100644 index 00000000..764c262c --- /dev/null +++ b/demo/Rabbit/pingpong.messages/pingpong.messages.csproj @@ -0,0 +1,55 @@ + + + + Debug + AnyCPU + 8.0.30703 + 2.0 + {EA3F4A1C-3248-4C71-A9F4-7CFF3ABF778A} + Library + Properties + pingpong.messages + pingpong.messages + v4.0 + 512 + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/demo/Rabbit/pong/Program.cs b/demo/Rabbit/pong/Program.cs new file mode 100644 index 00000000..99532297 --- /dev/null +++ b/demo/Rabbit/pong/Program.cs @@ -0,0 +1,58 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using pingpong.messages; +using Symbiote.Core; +using Symbiote.Core.Extensions; +using Symbiote.Daemon; +using Symbiote.Log4Net; +using Symbiote.Messaging; +using Symbiote.Rabbit; + +namespace pong +{ + class Program + { + static void Main(string[] args) + { + Assimilate + .Initialize() + .Rabbit( x => x.AddBroker( b => b.Defaults() ) ) + .AddConsoleLogger( x => x.Debug().MessageLayout( m => m.Message().Newline() ) ) + .Daemon( x => x.Name( "pong" ) ) + .RunDaemon(); + } + } + + public class PongService : IDaemon + { + public IBus Bus { get; set; } + + public void Start() + { + Bus.AddRabbitChannel( x => x.Direct( "ping" ) ); + Bus.AddRabbitQueue( x => x.ExchangeName( "ping" ).QueueName( "ping" ).NoAck().StartSubscription() ); + } + + public void Stop() + { + + } + + public PongService( IBus bus ) + { + Bus = bus; + } + } + + public class PingHandler : IHandle + { + public Action Handle( Ping message ) + { + "Received Ping!".ToInfo(); + return x => x.Reply( new Pong() ); + } + } +} diff --git a/demo/Rabbit/pong/Properties/AssemblyInfo.cs b/demo/Rabbit/pong/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..4fd39b4e --- /dev/null +++ b/demo/Rabbit/pong/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("pong")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Microsoft")] +[assembly: AssemblyProduct("pong")] +[assembly: AssemblyCopyright("Copyright © Microsoft 2011")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("cdb79f1e-3397-4f6d-b061-b7a479890104")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/demo/Rabbit/pong/app.config b/demo/Rabbit/pong/app.config new file mode 100644 index 00000000..e3656033 --- /dev/null +++ b/demo/Rabbit/pong/app.config @@ -0,0 +1,3 @@ + + + diff --git a/demo/Rabbit/pong/pong.csproj b/demo/Rabbit/pong/pong.csproj new file mode 100644 index 00000000..41ace0ca --- /dev/null +++ b/demo/Rabbit/pong/pong.csproj @@ -0,0 +1,91 @@ + + + + Debug + x86 + 8.0.30703 + 2.0 + {E474F71A-CB4B-42DA-89F3-4D242E847275} + Exe + Properties + pong + pong + v4.0 + + + 512 + + + x86 + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + x86 + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\..\..\bin\debug\CommandLine.dll + + + ..\..\..\bin\debug\log4net.dll + + + ..\..\..\bin\debug\RabbitMQ.Client.dll + + + ..\..\..\bin\debug\Symbiote.Core.dll + + + ..\..\..\bin\debug\Symbiote.Daemon.dll + + + ..\..\..\bin\debug\Symbiote.Log4Net.dll + + + ..\..\..\bin\debug\Symbiote.Messaging.dll + + + ..\..\..\bin\debug\Symbiote.Rabbit.dll + + + + + + + + + + + + + + + + + + + {EA3F4A1C-3248-4C71-A9F4-7CFF3ABF778A} + pingpong.messages + + + + + \ No newline at end of file diff --git a/src/Symbiote.Messaging/IHandle.cs b/src/Symbiote.Messaging/IHandle.cs index 894c6dd9..4d038454 100644 --- a/src/Symbiote.Messaging/IHandle.cs +++ b/src/Symbiote.Messaging/IHandle.cs @@ -21,12 +21,17 @@ public interface IHandle { } - public interface IHandle + public interface IHandle : IHandle { Action Handle( TMessage message ); } + public interface IHandleCompetitively + : IHandle + { + } + public interface IHandle : IHandle where TActor : class diff --git a/src/Symbiote.Messaging/Impl/IProvideMessagingConventions.cs b/src/Symbiote.Messaging/Impl/IProvideMessagingConventions.cs new file mode 100644 index 00000000..24130c61 --- /dev/null +++ b/src/Symbiote.Messaging/Impl/IProvideMessagingConventions.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Symbiote.Messaging.Impl +{ + public interface IProvideMessagingConventions + { + void CreateCompetingQueues(); + void CreateConsumerExchange(); + void CreateConsumerQueue(); + void CreateExchangeToExchangeBindings(); + void CreateTypeBasedExchanges(); + void CreateWireTaps(); + void StartSubscriptions(); + } +} diff --git a/src/Symbiote.Messaging/Symbiote.Messaging.csproj b/src/Symbiote.Messaging/Symbiote.Messaging.csproj index fb9086c5..d3b86ed4 100644 --- a/src/Symbiote.Messaging/Symbiote.Messaging.csproj +++ b/src/Symbiote.Messaging/Symbiote.Messaging.csproj @@ -100,6 +100,7 @@ + diff --git a/tests/Messaging.Tests/Messaging.Tests.csproj b/tests/Messaging.Tests/Messaging.Tests.csproj index f881350a..c8bb0268 100644 --- a/tests/Messaging.Tests/Messaging.Tests.csproj +++ b/tests/Messaging.Tests/Messaging.Tests.csproj @@ -49,9 +49,6 @@ ..\..\lib\protobuf-net\protobuf-net.dll - - ..\..\lib\StructureMap\StructureMap.dll - @@ -95,7 +92,14 @@ + + + + + + + Code @@ -115,10 +119,6 @@ {22173E83-BA63-4C4D-A1B3-D0D06DC55333} Symbiote.Messaging - - {DDC65B9C-20CC-4ECA-82A9-DC98D78CC12A} - Symbiote.StructureMap - diff --git a/tests/Messaging.Tests/Sagas/Person.cs b/tests/Messaging.Tests/Sagas/Person.cs new file mode 100644 index 00000000..26e81894 --- /dev/null +++ b/tests/Messaging.Tests/Sagas/Person.cs @@ -0,0 +1,16 @@ +using System; + +namespace Actor.Tests.Sagas +{ + public class Person + { + public Guid Id { get; set; } + public string Name { get; set; } + public bool Initialized { get; set; } + + public Person() + { + Id = Guid.Empty; + } + } +} \ No newline at end of file diff --git a/tests/Messaging.Tests/Sagas/PersonFactory.cs b/tests/Messaging.Tests/Sagas/PersonFactory.cs new file mode 100644 index 00000000..4f910ca1 --- /dev/null +++ b/tests/Messaging.Tests/Sagas/PersonFactory.cs @@ -0,0 +1,12 @@ +using Symbiote.Core.Actor; + +namespace Actor.Tests.Sagas +{ + public class PersonFactory : IActorFactory + { + public Person CreateInstance( TKey id ) + { + return new Person(); + } + } +} \ No newline at end of file diff --git a/tests/Messaging.Tests/Sagas/PersonKeyAccessor.cs b/tests/Messaging.Tests/Sagas/PersonKeyAccessor.cs new file mode 100644 index 00000000..6f593a02 --- /dev/null +++ b/tests/Messaging.Tests/Sagas/PersonKeyAccessor.cs @@ -0,0 +1,18 @@ +using System; +using Symbiote.Core; + +namespace Actor.Tests.Sagas +{ + public class PersonKeyAccessor : IKeyAccessor + { + public string GetId( Person actor ) + { + return actor.Id.ToString(); + } + + public void SetId( Person actor, TKey key ) + { + actor.Id = Guid.Parse( key.ToString() ); + } + } +} \ No newline at end of file diff --git a/tests/Messaging.Tests/Sagas/SetPersonName.cs b/tests/Messaging.Tests/Sagas/SetPersonName.cs new file mode 100644 index 00000000..ab8d4b2b --- /dev/null +++ b/tests/Messaging.Tests/Sagas/SetPersonName.cs @@ -0,0 +1,15 @@ +using System; + +namespace Actor.Tests.Sagas +{ + public class SetPersonName + { + public Guid PersonId { get; set; } + public string Name { get; set; } + + public SetPersonName() + { + PersonId = Guid.Empty; + } + } +} \ No newline at end of file diff --git a/tests/Messaging.Tests/Sagas/TestSaga.cs b/tests/Messaging.Tests/Sagas/TestSaga.cs new file mode 100644 index 00000000..8d7447b9 --- /dev/null +++ b/tests/Messaging.Tests/Sagas/TestSaga.cs @@ -0,0 +1,33 @@ +using System; +using Symbiote.Messaging; +using Symbiote.Messaging.Impl.Saga; + +namespace Actor.Tests.Sagas +{ + public class TestSaga + : Saga + { + public override Action> Setup() + { + return x => + { + x.When( p => !p.Initialized ) + .On( ( p, m ) => + { + p.Name = m.Name; + p.Initialized = true; + return e => e.Acknowledge(); + }); + + x.When( p => p.Initialized ) + .On( ( p, m ) => + { + p.Name = "Reset"; + return e => e.Acknowledge(); + } ); + }; + } + + public TestSaga( StateMachine stateMachine ) : base( stateMachine ) {} + } +} \ No newline at end of file diff --git a/tests/Messaging.Tests/Sagas/when_requesting_saga.cs b/tests/Messaging.Tests/Sagas/when_requesting_saga.cs index 857eb9f9..414ad507 100644 --- a/tests/Messaging.Tests/Sagas/when_requesting_saga.cs +++ b/tests/Messaging.Tests/Sagas/when_requesting_saga.cs @@ -1,87 +1,12 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; -using System.Threading; using Machine.Specifications; using Messaging.Tests; using Symbiote.Core; -using Symbiote.Core.Actor; -using Symbiote.Messaging; using Symbiote.Messaging.Impl.Saga; namespace Actor.Tests.Sagas { - public class Person - { - public Guid Id { get; set; } - public string Name { get; set; } - public bool Initialized { get; set; } - - public Person() - { - Id = Guid.Empty; - } - } - - public class PersonKeyAccessor : IKeyAccessor - { - public string GetId( Person actor ) - { - return actor.Id.ToString(); - } - - public void SetId( Person actor, TKey key ) - { - actor.Id = Guid.Parse( key.ToString() ); - } - } - - public class PersonFactory : IActorFactory - { - public Person CreateInstance( TKey id ) - { - return new Person(); - } - } - - public class SetPersonName - { - public Guid PersonId { get; set; } - public string Name { get; set; } - - public SetPersonName() - { - PersonId = Guid.Empty; - } - } - - public class TestSaga - : Saga - { - public override Action> Setup() - { - return x => - { - x.When( p => !p.Initialized ) - .On( ( p, m ) => - { - p.Name = m.Name; - p.Initialized = true; - return e => e.Acknowledge(); - }); - - x.When( p => p.Initialized ) - .On( ( p, m ) => - { - p.Name = "Reset"; - return e => e.Acknowledge(); - } ); - }; - } - - public TestSaga( StateMachine stateMachine ) : base( stateMachine ) {} - } - public class when_requesting_saga : with_assimilation { @@ -95,32 +20,4 @@ public class when_requesting_saga private It should_not_be_empty = () => Sagas.Count().ShouldBeGreaterThan( 0 ); } - - public class with_bus - : with_assimilation - { - public static IBus Bus { get; set; } - private Establish context = () => - { - Bus = Assimilate.GetInstanceOf(); - Bus.AddLocalChannel(x => x.CorrelateBy( m => m.PersonId.ToString() )); - }; - } - - public class when_sending_command_to_saga - : with_bus - { - public static IAgent Agent { get; set; } - public static Person person { get; set; } - private Because of = () => - { - Bus.Publish( "local", new SetPersonName() {Name = "Bob"} ); - Bus.Publish( "local", new SetPersonName() {Name = "Bob"} ); - Thread.Sleep( 50 ); - Agent = Assimilate.GetInstanceOf>(); - person = Agent.GetActor( Guid.Empty.ToString() ); - }; - - private It should_name_should_reset = () => person.Name.ShouldEqual( "Reset" ); - } } diff --git a/tests/Messaging.Tests/Sagas/when_sending_command_to_saga.cs b/tests/Messaging.Tests/Sagas/when_sending_command_to_saga.cs new file mode 100644 index 00000000..2efe569f --- /dev/null +++ b/tests/Messaging.Tests/Sagas/when_sending_command_to_saga.cs @@ -0,0 +1,25 @@ +using System; +using System.Threading; +using Machine.Specifications; +using Symbiote.Core; +using Symbiote.Core.Actor; + +namespace Actor.Tests.Sagas +{ + public class when_sending_command_to_saga + : with_bus + { + public static IAgent Agent { get; set; } + public static Person person { get; set; } + private Because of = () => + { + Bus.Publish( "local", new SetPersonName() {Name = "Bob"} ); + Bus.Publish( "local", new SetPersonName() {Name = "Bob"} ); + Thread.Sleep( 50 ); + Agent = Assimilate.GetInstanceOf>(); + person = Agent.GetActor( Guid.Empty.ToString() ); + }; + + private It should_name_should_reset = () => person.Name.ShouldEqual( "Reset" ); + } +} \ No newline at end of file diff --git a/tests/Messaging.Tests/Sagas/with_bus.cs b/tests/Messaging.Tests/Sagas/with_bus.cs new file mode 100644 index 00000000..9707cdda --- /dev/null +++ b/tests/Messaging.Tests/Sagas/with_bus.cs @@ -0,0 +1,18 @@ +using Machine.Specifications; +using Messaging.Tests; +using Symbiote.Core; +using Symbiote.Messaging; + +namespace Actor.Tests.Sagas +{ + public class with_bus + : with_assimilation + { + public static IBus Bus { get; set; } + private Establish context = () => + { + Bus = Assimilate.GetInstanceOf(); + Bus.AddLocalChannel(x => x.CorrelateBy( m => m.PersonId.ToString() )); + }; + } +} \ No newline at end of file diff --git a/tests/Messaging.Tests/with_assimilation.cs b/tests/Messaging.Tests/with_assimilation.cs index c4f26e78..35727fc3 100644 --- a/tests/Messaging.Tests/with_assimilation.cs +++ b/tests/Messaging.Tests/with_assimilation.cs @@ -1,7 +1,6 @@ using Machine.Specifications; using Symbiote.Core; using Symbiote.Messaging; -using Symbiote.StructureMapAdapter; namespace Messaging.Tests {