├── ClickToBuild.bat ├── tools ├── MSBuild │ ├── BuildSupport │ │ ├── mspecTemplate.bat │ │ ├── MSpecConfig │ │ │ ├── mspec-clr4.exe.config │ │ │ └── mspec-x86-clr4.config │ │ └── Common.targets.properties │ ├── SouthSideBuildTasks │ │ ├── SouthSide.Core.dll │ │ ├── SouthSideBuildTasks.MSBuild.dll │ │ └── SouthSideBuildTasks.MSBuild.Tasks.Targets │ └── MSBuildCommunityTasks │ │ ├── MSBuild.Community.Tasks.chm │ │ └── MSBuild.Community.Tasks.dll ├── NuGet.exe ├── NuGet.config └── pushtonuget.cmd ├── msbuild.bat ├── src ├── Samples │ ├── PubSubUsingNinject │ │ ├── app.config │ │ ├── Properties │ │ │ └── AssemblyInfo.cs │ │ ├── packages.config │ │ └── Bootstrapper.cs │ ├── PubSubUsingUnity │ │ ├── app.config │ │ ├── Properties │ │ │ └── AssemblyInfo.cs │ │ ├── packages.config │ │ └── Bootstrapper.cs │ ├── PubSubUsingCastleWindsor │ │ ├── app.config │ │ ├── Properties │ │ │ └── AssemblyInfo.cs │ │ ├── packages.config │ │ └── Bootstrapper.cs │ ├── PubSubUsingStructureMap │ │ ├── app.config │ │ ├── Properties │ │ │ └── AssemblyInfo.cs │ │ ├── packages.config │ │ └── Bootstrapper.cs │ └── PubSubUsingConfiguration │ │ ├── TestMessage.cs │ │ ├── AnotherTestMessage.cs │ │ ├── packages.config │ │ ├── Properties │ │ └── AssemblyInfo.cs │ │ ├── TestMessageSubscriber.cs │ │ ├── AnotherTestMessageSubscriber.cs │ │ ├── Bootstrapper.cs │ │ └── GZipXmlSerializer.cs ├── ProjectExtensions.Azure.ServiceBus.Autofac │ ├── packages.config │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Container │ │ ├── AutofacBusConfigurationBuilderExtensions.cs │ │ └── AutofacAzureBusContainer.cs │ └── ProjectExtensions.Azure.ServiceBus.Autofac.csproj ├── ProjectExtensions.Azure.ServiceBus.Ninject │ ├── packages.config │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Container │ │ ├── NinjectBusConfigurationBuilderExtensions.cs │ │ └── NinjectAzureBusContainer.cs │ └── ProjectExtensions.Azure.ServiceBus.Ninject.csproj ├── ProjectExtensions.Azure.ServiceBus.StructureMap │ ├── packages.config │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Container │ │ ├── StructureMapBusConfigurationBuilderExtensions.cs │ │ └── StructureMapAzureBusContainer.cs │ └── ProjectExtensions.Azure.ServiceBus.StructureMap.csproj ├── ProjectExtensions.Azure.ServiceBus.Unity │ ├── packages.config │ ├── Properties │ │ └── AssemblyInfo.cs │ └── Container │ │ ├── UnityBusConfigurationBuilderExtensions.cs │ │ └── UnityAzureBusContainer.cs ├── ProjectExtensions.Azure.ServiceBus.CastleWindsor │ ├── packages.config │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Container │ │ ├── CastleWindsorBusConfigurationBuilderExtensions.cs │ │ └── CastleWindsorBusContainer.cs │ └── ProjectExtensions.Azure.ServiceBus.CastleWindsor.csproj ├── Tests │ ├── ProjectExtensions.Azure.ServiceBus.Tests.Integration │ │ ├── packages.config │ │ ├── Properties │ │ │ └── AssemblyInfo.cs │ │ └── ProjectExtensions.Azure.ServiceBus.Tests.Integration.csproj │ └── ProjectExtensions.Azure.ServiceBus.Tests.Unit │ │ ├── SampleTest.cs │ │ ├── packages.config │ │ ├── Messages │ │ └── TestMessageForTesting.cs │ │ ├── Properties │ │ └── AssemblyInfo.cs │ │ ├── Handlers │ │ └── TestMessageForTestingHandler.cs │ │ ├── Mocks │ │ ├── MockIAsyncResult.cs │ │ ├── MockMessagingFactory.cs │ │ ├── MockNamespaceManager.cs │ │ ├── MockTopicClient.cs │ │ └── MockSubscriptionClient.cs │ │ ├── Interfaces │ │ └── IMockServiceBus.cs │ │ ├── Config.cs │ │ └── app.config ├── ProjectExtensions.Azure.ServiceBus │ ├── Interfaces │ │ ├── IAzureBusReceiver.cs │ │ ├── ITopicClient.cs │ │ ├── IServiceBusTokenProvider.cs │ │ ├── IServiceBusConfigurationFactory.cs │ │ ├── IMessagingFactory.cs │ │ ├── ISubscriptionClient.cs │ │ ├── INamespaceManager.cs │ │ ├── IAzureBusSender.cs │ │ └── IServiceBusSetupConfiguration.cs │ ├── SingletonMessageHandlerAttribute.cs │ ├── packages.config │ ├── Exceptions │ │ └── TopicDeletedException.cs │ ├── Sender │ │ └── MessageSentResult.cs │ ├── Properties │ │ └── AssemblyInfo.cs │ ├── Helpers │ │ ├── MD5Helper.cs │ │ ├── ReflectionHelper.cs │ │ └── BusHelper.cs │ ├── ExtensionMethods.cs │ ├── CloudEnvironment.cs │ ├── AnonymousDisposable.cs │ ├── IReceivedMessage.cs │ ├── TransientFaultHandling │ │ ├── ServiceBus │ │ │ └── ServiceBusTransientErrorToDetermineExistanceDetectionStrategy.cs │ │ ├── ExtensionMethods.cs │ │ ├── AzureStorage │ │ │ └── AzureStorageExtensions.cs │ │ ├── RetryPolicyException.cs │ │ ├── GlobalSuppressions.cs │ │ └── Configuration │ │ │ └── TransientFaultHandlingDesignTime.cs │ ├── IMessageSentResult.cs │ ├── Wrappers │ │ ├── TopicClientWrapper.cs │ │ └── SubscriptionClientWrapper.cs │ ├── Factories │ │ └── GenericServiceBusConfigurationFactory.cs │ ├── Receiver │ │ ├── ReceivedMessage.cs │ │ ├── AzureBusReceiverState.cs │ │ └── AzureReceiveState.cs │ ├── Serialization │ │ ├── IServiceBusSerializer.cs │ │ ├── ServiceBusSerializerBase.cs │ │ ├── XmlServiceBusSerializer.cs │ │ └── JsonServiceBusSerializer.cs │ ├── TransientFaultHandling.Core │ │ ├── ITransientErrorDetectionStrategy.cs │ │ ├── RetryingEventArgs.cs │ │ ├── Properties │ │ │ └── Resources.Designer.cs │ │ ├── RetryLimitExceededException.cs │ │ └── RetryPolicy.Generic.cs │ ├── AzureServiceBusFactories │ │ ├── ServiceBusTokenProvider.cs │ │ ├── ServiceBusMessagingFactoryFactory.cs │ │ └── ServiceBusNamespaceManagerFactory.cs │ ├── IMessageHandler.cs │ ├── Container │ │ ├── IAzureBusContainer.cs │ │ └── AzureBusContainerBase.cs │ ├── ServiceBusEnpointData.cs │ ├── ServiceBusSetupConfiguration.cs │ ├── IBusConfiguration.cs │ ├── IBus.cs │ ├── app.config │ └── BrokeredMessageWrapper.cs └── CommonAssemblyInfo.cs ├── lib └── Microsoft.WindowsAzure.StorageClient.dll ├── .gitignore ├── .hgignore ├── packages └── repositories.config ├── license.txt ├── ProjectExtensions.Azure.ServiceBus.IOC.Unity.nuspec ├── ProjectExtensions.Azure.ServiceBus.IOC.Autofac.nuspec ├── ProjectExtensions.Azure.ServiceBus.IOC.Ninject.nuspec ├── ProjectExtensions.Azure.ServiceBus.IOC.StructureMap.nuspec ├── ProjectExtensions.Azure.ServiceBus.IOC.CastleWindsor.nuspec ├── ProjectExtensions.Azure.ServiceBus.Core.nuspec └── ProjectExtensions.Azure.ServiceBus.nuspec /ClickToBuild.bat: -------------------------------------------------------------------------------- 1 | call build.bat 2 | pause 3 | -------------------------------------------------------------------------------- /tools/MSBuild/BuildSupport/mspecTemplate.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | "${mspecTestRunner}" %* -------------------------------------------------------------------------------- /msbuild.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | %systemroot%\Microsoft.NET\Framework\v4.0.30319\msbuild.exe %* -------------------------------------------------------------------------------- /src/Samples/PubSubUsingNinject/app.config: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/Samples/PubSubUsingUnity/app.config: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/Samples/PubSubUsingCastleWindsor/app.config: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /src/Samples/PubSubUsingStructureMap/app.config: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /tools/NuGet.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ProjectExtensions/ProjectExtensions.Azure.ServiceBus/HEAD/tools/NuGet.exe -------------------------------------------------------------------------------- /lib/Microsoft.WindowsAzure.StorageClient.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ProjectExtensions/ProjectExtensions.Azure.ServiceBus/HEAD/lib/Microsoft.WindowsAzure.StorageClient.dll -------------------------------------------------------------------------------- /tools/MSBuild/SouthSideBuildTasks/SouthSide.Core.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ProjectExtensions/ProjectExtensions.Azure.ServiceBus/HEAD/tools/MSBuild/SouthSideBuildTasks/SouthSide.Core.dll -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus.Autofac/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /tools/NuGet.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus.Ninject/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus.StructureMap/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /tools/MSBuild/MSBuildCommunityTasks/MSBuild.Community.Tasks.chm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ProjectExtensions/ProjectExtensions.Azure.ServiceBus/HEAD/tools/MSBuild/MSBuildCommunityTasks/MSBuild.Community.Tasks.chm -------------------------------------------------------------------------------- /tools/MSBuild/MSBuildCommunityTasks/MSBuild.Community.Tasks.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ProjectExtensions/ProjectExtensions.Azure.ServiceBus/HEAD/tools/MSBuild/MSBuildCommunityTasks/MSBuild.Community.Tasks.dll -------------------------------------------------------------------------------- /tools/MSBuild/SouthSideBuildTasks/SouthSideBuildTasks.MSBuild.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ProjectExtensions/ProjectExtensions.Azure.ServiceBus/HEAD/tools/MSBuild/SouthSideBuildTasks/SouthSideBuildTasks.MSBuild.dll -------------------------------------------------------------------------------- /tools/MSBuild/BuildSupport/MSpecConfig/mspec-clr4.exe.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /tools/MSBuild/BuildSupport/MSpecConfig/mspec-x86-clr4.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus.Unity/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus.CastleWindsor/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /src/Tests/ProjectExtensions.Azure.ServiceBus.Tests.Integration/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/Interfaces/IAzureBusReceiver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ProjectExtensions.Azure.ServiceBus.Interfaces { 4 | 5 | interface IAzureBusReceiver { 6 | void CancelSubscription(ServiceBusEnpointData value); 7 | void CreateSubscription(ServiceBusEnpointData value); 8 | void Dispose(bool disposing); 9 | long MessageCountForType(Type type); 10 | } 11 | 12 | } 13 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/SingletonMessageHandlerAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ProjectExtensions.Azure.ServiceBus { 4 | /// 5 | /// Marks message handler as a singleton. 6 | /// 7 | [Obsolete("Use the Singleton property of MessageHandlerConfiguration", true)] 8 | [AttributeUsage(AttributeTargets.Class)] 9 | public class SingletonMessageHandlerAttribute : Attribute {} 10 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | #ignore thumbnails created by windows 3 | Thumbs.db 4 | #Ignore files build by Visual Studio 5 | *.obj 6 | *.exe 7 | *.pdb 8 | *.user 9 | *.aps 10 | *.pch 11 | *.vspscc 12 | *_i.c 13 | *_p.c 14 | *.ncb 15 | *.suo 16 | *.tlb 17 | *.tlh 18 | *.bak 19 | *.cache 20 | *.ilk 21 | *.log 22 | [Bb]in 23 | [Dd]ebug*/ 24 | *.lib 25 | *.sbr 26 | obj/ 27 | [Rr]elease*/ 28 | _ReSharper*/ 29 | [Tt]est[Rr]esult* 30 | .hg/ 31 | BuildOutput/* 32 | packages/* -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /src/Samples/PubSubUsingConfiguration/TestMessage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace PubSubUsingConfiguration { 7 | 8 | public class TestMessage { 9 | 10 | public string MessageId { 11 | get; 12 | set; 13 | } 14 | 15 | public int Value { 16 | get; 17 | set; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /tools/MSBuild/SouthSideBuildTasks/SouthSideBuildTasks.MSBuild.Tasks.Targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | .\\SouthSideBuildTasks.MSBuild.dll 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/Samples/PubSubUsingNinject/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("PubSubUsingNinject")] 9 | [assembly: AssemblyDescription("")] 10 | -------------------------------------------------------------------------------- /src/Samples/PubSubUsingUnity/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("PubSubUsingUnity")] 9 | [assembly: AssemblyDescription("")] 10 | -------------------------------------------------------------------------------- /src/Samples/PubSubUsingConfiguration/AnotherTestMessage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace PubSubUsingConfiguration { 7 | 8 | public class AnotherTestMessage { 9 | 10 | public string MessageId { 11 | get; 12 | set; 13 | } 14 | 15 | public int Value { 16 | get; 17 | set; 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Samples/PubSubUsingStructureMap/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("PubSubUsingStructureMap")] 9 | [assembly: AssemblyDescription("")] 10 | -------------------------------------------------------------------------------- /src/Samples/PubSubUsingCastleWindsor/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("PubSubUsingCastleWindsor")] 9 | [assembly: AssemblyDescription("")] 10 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus.Autofac/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("ProjectExtensions.Azure.ServiceBus.Autofac")] 9 | [assembly: AssemblyDescription("")] 10 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/Interfaces/ITopicClient.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Microsoft.ServiceBus.Messaging; 6 | 7 | namespace ProjectExtensions.Azure.ServiceBus.Interfaces { 8 | 9 | interface ITopicClient { 10 | IAsyncResult BeginSend(IBrokeredMessage message, AsyncCallback callback, object state); 11 | void EndSend(IAsyncResult result); 12 | void Close(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus.StructureMap/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("ProjectExtensions.Azure.ServiceBus.StructureMap")] 9 | [assembly: AssemblyDescription("")] 10 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/Interfaces/IServiceBusTokenProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Microsoft.ServiceBus; 6 | 7 | namespace ProjectExtensions.Azure.ServiceBus.Interfaces { 8 | 9 | interface IServiceBusTokenProvider { 10 | 11 | TokenProvider TokenProvider { 12 | get; 13 | } 14 | 15 | Uri ServiceUri { 16 | get; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus.CastleWindsor/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("ProjectExtensions.Azure.ServiceBus.CastleWindsor")] 9 | [assembly: AssemblyDescription("")] 10 | -------------------------------------------------------------------------------- /src/Samples/PubSubUsingNinject/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/Samples/PubSubUsingConfiguration/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/Samples/PubSubUsingStructureMap/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/Tests/ProjectExtensions.Azure.ServiceBus.Tests.Unit/SampleTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using NUnit.Framework; 6 | using System.Threading; 7 | 8 | namespace ProjectExtensions.Azure.ServiceBus.Tests.Unit { 9 | 10 | [TestFixture] 11 | public class SampleTest { 12 | 13 | [Test] 14 | public void Test() { 15 | //Thread.Sleep(10000); 16 | Assert.IsTrue(true); 17 | } 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/Samples/PubSubUsingUnity/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/Samples/PubSubUsingCastleWindsor/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/Tests/ProjectExtensions.Azure.ServiceBus.Tests.Unit/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/Interfaces/IServiceBusConfigurationFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Microsoft.ServiceBus; 6 | using Microsoft.ServiceBus.Messaging; 7 | using System.IO; 8 | 9 | namespace ProjectExtensions.Azure.ServiceBus.Interfaces { 10 | 11 | interface IServiceBusConfigurationFactory { 12 | 13 | IMessagingFactory MessageFactory { 14 | get; 15 | } 16 | 17 | INamespaceManager NamespaceManager { 18 | get; 19 | } 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus.Ninject/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("ProjectExtensions.Azure.ServiceBus.Ninject")] 9 | 10 | // The following GUID is for the ID of the typelib if this project is exposed to COM 11 | [assembly: Guid("109b7324-ddb5-4f69-a1ef-f362110a8d2e")] 12 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus.Unity/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("ProjectExtensions.Azure.ServiceBus.Unity")] 9 | 10 | // The following GUID is for the ID of the typelib if this project is exposed to COM 11 | [assembly: Guid("34aaef93-1320-41a0-b034-5e88a8da4fc9")] 12 | 13 | -------------------------------------------------------------------------------- /.hgignore: -------------------------------------------------------------------------------- 1 | syntax: glob 2 | #ignore outputs of project 3 | BuildOutput*/ 4 | TestResults*/ 5 | #ignore thumbnails created by windows 6 | Thumbs.db 7 | #Ignore files build by Visual Studio 8 | *.obj 9 | *.user 10 | *.aps 11 | *.pch 12 | *.vspscc 13 | *_i.c 14 | *_p.c 15 | *.ncb 16 | *.suo 17 | *.tlb 18 | *.tlh 19 | *.bak 20 | *.cache 21 | *.ilk 22 | *.log 23 | *.orig 24 | [Bb]in 25 | [Dd]ebug*/ 26 | *.lib 27 | *.sbr 28 | obj/ 29 | [Rr]elease*/ 30 | doc/ 31 | _ReSharper*/ 32 | [Tt]est[Rr]esult* 33 | zzz_* 34 | Files/temp/** 35 | _[Bb]ackup*/* 36 | _[Uu]pgrade*/* 37 | relre:/*.ReSharper 38 | packages/*/* 39 | src/*.exe.config 40 | .git/** 41 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/Interfaces/IMessagingFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Microsoft.ServiceBus.Messaging; 6 | using Microsoft.ServiceBus; 7 | using System.IO; 8 | 9 | namespace ProjectExtensions.Azure.ServiceBus.Interfaces { 10 | 11 | interface IMessagingFactory { 12 | ISubscriptionClient CreateSubscriptionClient(string topicPath, string name, ReceiveMode receiveMode); 13 | ITopicClient CreateTopicClient(string path); 14 | void Close(); 15 | IBrokeredMessage CreateBrokeredMessage(Stream messageBodyStream); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/Exceptions/TopicDeletedException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace ProjectExtensions.Azure.ServiceBus.Exceptions { 7 | 8 | /// 9 | /// Exception that is returned when a topic is deleted 10 | /// 11 | public class TopicDeletedException : Exception { 12 | 13 | /// 14 | /// Create a new exception. 15 | /// 16 | public TopicDeletedException() 17 | : base("Topic was deleted during execution but was recreated. Message could not be sent.") { 18 | } 19 | 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/Interfaces/ISubscriptionClient.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Microsoft.ServiceBus.Messaging; 6 | 7 | namespace ProjectExtensions.Azure.ServiceBus.Interfaces { 8 | 9 | interface ISubscriptionClient { 10 | 11 | int PrefetchCount { 12 | get; 13 | set; 14 | } 15 | 16 | void OnMessage(Action callback, OnMessageOptions onMessageOptions); 17 | 18 | bool IsClosed { get; } 19 | 20 | void Close(); 21 | 22 | ReceiveMode Mode { 23 | get; 24 | } 25 | 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/Samples/PubSubUsingConfiguration/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("PubSubUsingConfiguration")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyTrademark("")] 11 | [assembly: AssemblyCulture("")] 12 | 13 | // The following GUID is for the ID of the typelib if this project is exposed to COM 14 | [assembly: Guid("1da1ded9-2716-4bcf-8ab6-96d5dc8e98f6")] 15 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/Sender/MessageSentResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace ProjectExtensions.Azure.ServiceBus.Sender { 7 | 8 | class MessageSentResult : IMessageSentResult { 9 | 10 | public bool IsSuccess { 11 | get; 12 | set; 13 | } 14 | 15 | public Exception ThrownException { 16 | get; 17 | set; 18 | } 19 | 20 | public TimeSpan TimeSpent { 21 | get; 22 | set; 23 | } 24 | 25 | public object State { 26 | get; 27 | set; 28 | } 29 | 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Tests/ProjectExtensions.Azure.ServiceBus.Tests.Unit/Messages/TestMessageForTesting.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace ProjectExtensions.Azure.ServiceBus.Tests.Unit.Messages { 7 | 8 | public class TestMessageForTesting { 9 | 10 | static int counter; 11 | 12 | public TestMessageForTesting() { 13 | Id = Guid.NewGuid(); 14 | counter++; 15 | this.Counter = counter; 16 | } 17 | 18 | public int Counter { 19 | get; 20 | set; 21 | } 22 | 23 | public Guid Id { 24 | get; 25 | set; 26 | } 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/Tests/ProjectExtensions.Azure.ServiceBus.Tests.Unit/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("ProjectExtensions.Azure.ServiceBus.Tests.Unit")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyTrademark("")] 11 | [assembly: AssemblyCulture("")] 12 | 13 | // The following GUID is for the ID of the typelib if this project is exposed to COM 14 | [assembly: Guid("022f5733-2f94-4bb8-bdd4-9bdd8f6826c0")] 15 | 16 | -------------------------------------------------------------------------------- /tools/pushtonuget.cmd: -------------------------------------------------------------------------------- 1 | rem nuget.exe setApiKey zzzzzz 2 | nuget.exe push ..\BuildOutput\NuGet\ProjectExtensions.Azure.ServiceBus.0.10.7.0.nupkg 3 | nuget.exe push ..\BuildOutput\NuGet\ProjectExtensions.Azure.ServiceBus.Core.0.10.7.0.nupkg 4 | nuget.exe push ..\BuildOutput\NuGet\ProjectExtensions.Azure.ServiceBus.IOC.Autofac.0.10.7.0.nupkg 5 | nuget.exe push ..\BuildOutput\NuGet\ProjectExtensions.Azure.ServiceBus.IOC.CastleWindsor.0.10.7.0.nupkg 6 | nuget.exe push ..\BuildOutput\NuGet\ProjectExtensions.Azure.ServiceBus.IOC.Ninject.0.10.7.0.nupkg 7 | nuget.exe push ..\BuildOutput\NuGet\ProjectExtensions.Azure.ServiceBus.IOC.StructureMap.0.10.7.0.nupkg 8 | nuget.exe push ..\BuildOutput\NuGet\ProjectExtensions.Azure.ServiceBus.IOC.Unity.0.10.7.0.nupkg 9 | 10 | -------------------------------------------------------------------------------- /src/Tests/ProjectExtensions.Azure.ServiceBus.Tests.Integration/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("ProjectExtensions.Azure.ServiceBus.Tests.Integration")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyTrademark("")] 11 | [assembly: AssemblyCulture("")] 12 | 13 | // The following GUID is for the ID of the typelib if this project is exposed to COM 14 | [assembly: Guid("cb679cce-c45c-4fc2-99e2-98f90146d8c6")] 15 | 16 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("ProjectExtensions.Azure.ServiceBus")] 9 | 10 | // The following GUID is for the ID of the typelib if this project is exposed to COM 11 | [assembly: Guid("94465007-1c7a-48e8-a8ad-317e52dd90f1")] 12 | 13 | [assembly: InternalsVisibleTo("ProjectExtensions.Azure.ServiceBus.Tests.Unit")] 14 | [assembly: InternalsVisibleTo("ProjectExtensions.Azure.ServiceBus.Tests.Integration")] 15 | -------------------------------------------------------------------------------- /src/Samples/PubSubUsingNinject/Bootstrapper.cs: -------------------------------------------------------------------------------- 1 | using ProjectExtensions.Azure.ServiceBus; 2 | using ProjectExtensions.Azure.ServiceBus.Ninject.Container; 3 | 4 | namespace PubSubUsingConfiguration { 5 | static internal class Bootstrapper { 6 | public static void Initialize() { 7 | BusConfiguration.WithSettings() 8 | .UseNinjectContainer() 9 | .ReadFromConfigFile() 10 | .ServiceBusApplicationId("AppName") 11 | //.ServiceBusIssuerKey("[sb password]") 12 | //.ServiceBusIssuerName("owner") 13 | //.ServiceBusNamespace("[addresshere]") 14 | .RegisterAssembly(typeof(TestMessageSubscriber).Assembly) 15 | .Configure(); 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /src/Samples/PubSubUsingUnity/Bootstrapper.cs: -------------------------------------------------------------------------------- 1 | using ProjectExtensions.Azure.ServiceBus; 2 | using ProjectExtensions.Azure.ServiceBus.Unity.Container; 3 | using PubSubUsingConfiguration; 4 | 5 | namespace PubSubUsingConfiguration { 6 | public static class Bootstrapper { 7 | public static void Initialize() { 8 | BusConfiguration.WithSettings() 9 | .UseUnityContainer() 10 | .ReadFromConfigFile() 11 | .ServiceBusApplicationId("AppName") 12 | //.ServiceBusIssuerKey("[sb password]") 13 | //.ServiceBusIssuerName("owner") 14 | //.ServiceBusNamespace("[addresshere]") 15 | .RegisterAssembly(typeof(TestMessageSubscriber).Assembly) 16 | .Configure(); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Samples/PubSubUsingStructureMap/Bootstrapper.cs: -------------------------------------------------------------------------------- 1 | using ProjectExtensions.Azure.ServiceBus; 2 | using ProjectExtensions.Azure.ServiceBus.StructureMap.Container; 3 | using PubSubUsingConfiguration; 4 | 5 | namespace PubSubUsingConfiguration { 6 | public static class Bootstrapper { 7 | public static void Initialize() { 8 | BusConfiguration.WithSettings() 9 | .UseStructureMapContainer() 10 | .ReadFromConfigFile() 11 | .ServiceBusApplicationId("AppName") 12 | //.ServiceBusIssuerKey("[sb password]") 13 | //.ServiceBusIssuerName("owner") 14 | //.ServiceBusNamespace("[addresshere]") 15 | .RegisterAssembly(typeof(TestMessageSubscriber).Assembly) 16 | .Configure(); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Samples/PubSubUsingCastleWindsor/Bootstrapper.cs: -------------------------------------------------------------------------------- 1 | using ProjectExtensions.Azure.ServiceBus; 2 | using ProjectExtensions.Azure.ServiceBus.CastleWindsor.Container; 3 | using PubSubUsingConfiguration; 4 | 5 | namespace PubSubUsingConfiguration { 6 | public static class Bootstrapper { 7 | public static void Initialize() { 8 | BusConfiguration.WithSettings() 9 | .UseCastleWindsorContainer() 10 | .ReadFromConfigFile() 11 | .ServiceBusApplicationId("AppName") 12 | //.ServiceBusIssuerKey("[sb password]") 13 | //.ServiceBusIssuerName("owner") 14 | //.ServiceBusNamespace("[addresshere]") 15 | .RegisterAssembly(typeof(TestMessageSubscriber).Assembly) 16 | .Configure(); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/Helpers/MD5Helper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Security.Cryptography; 6 | 7 | namespace ProjectExtensions.Azure.ServiceBus.Helpers { 8 | 9 | class MD5Helper { 10 | 11 | /// 12 | /// Calculates MD5 hash 13 | /// 14 | /// input string 15 | /// MD5 hash 16 | public static string CalculateMD5(string text) { 17 | byte[] buffer = UTF8Encoding.UTF8.GetBytes(text); 18 | var cryptoTransformSHA1 = new MD5CryptoServiceProvider(); 19 | string hash = BitConverter.ToString( 20 | cryptoTransformSHA1.ComputeHash(buffer)).Replace("-", ""); 21 | 22 | return hash; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/Tests/ProjectExtensions.Azure.ServiceBus.Tests.Unit/Handlers/TestMessageForTestingHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using ProjectExtensions.Azure.ServiceBus.Tests.Unit.Messages; 6 | using System.Diagnostics; 7 | 8 | namespace ProjectExtensions.Azure.ServiceBus.Tests.Unit.Handlers { 9 | 10 | public class TestMessageForTestingHandler : IHandleMessages { 11 | 12 | public void Handle(IReceivedMessage message) { 13 | Debug.WriteLine("Received:" + message.BrokeredMessage.MessageId + " Value:" + message.Message.Id + " counter:" + message.Message.Counter); 14 | Console.WriteLine("Received:" + message.BrokeredMessage.MessageId + " Value:" + message.Message.Id + " counter:" + message.Message.Counter); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/ExtensionMethods.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using NLog; 6 | 7 | namespace ProjectExtensions.Azure.ServiceBus { 8 | 9 | /// 10 | /// Extension Methods 11 | /// 12 | public static class ExtensionMethods { 13 | 14 | static Logger logger = LogManager.GetCurrentClassLogger(); 15 | 16 | 17 | /// 18 | /// Execute and catch any exception that is thrown and swallow it. 19 | /// 20 | /// The action to perform 21 | public static void ExecuteAndReturn(Action action) { 22 | try { 23 | action(); 24 | } 25 | catch (Exception ex) { 26 | logger.Error("ExecuteAndReturn Failed {0}", ex); 27 | } 28 | } 29 | 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/Interfaces/INamespaceManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Microsoft.ServiceBus.Messaging; 6 | using Microsoft.ServiceBus; 7 | 8 | namespace ProjectExtensions.Azure.ServiceBus.Interfaces { 9 | 10 | /// 11 | /// Interface used to abstract the NamespaceManager 12 | /// 13 | interface INamespaceManager { 14 | 15 | SubscriptionDescription CreateSubscription(SubscriptionDescription description, Filter filter); 16 | TopicDescription CreateTopic(TopicDescription description); 17 | 18 | void DeleteSubscription(string topicPath, string name); 19 | 20 | SubscriptionDescription GetSubscription(string topicPath, string name); 21 | TopicDescription GetTopic(string path); 22 | 23 | bool SubscriptionExists(string topicPath, string name); 24 | 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus.Autofac/Container/AutofacBusConfigurationBuilderExtensions.cs: -------------------------------------------------------------------------------- 1 | using Autofac; 2 | 3 | namespace ProjectExtensions.Azure.ServiceBus.Autofac.Container { 4 | /// 5 | /// Extensions to allow configuration using Autofac 6 | /// 7 | public static class AutofacBusConfigurationBuilderExtensions { 8 | /// 9 | /// Initializes Autofac 10 | /// 11 | /// 12 | /// Autofac container used in your application. This is optional. A new container will be created if one is not provided 13 | /// 14 | public static BusConfigurationBuilder UseAutofacContainer(this BusConfigurationBuilder builder, IContainer container = null) { 15 | builder.Configuration.Container = new AutofacAzureBusContainer(container); 16 | return builder; 17 | } 18 | 19 | } 20 | } -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/CloudEnvironment.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Web; 6 | 7 | namespace ProjectExtensions.Azure.ServiceBus { 8 | 9 | static class CloudEnvironment { 10 | 11 | /// 12 | /// Ensures that the HttpContext object is safe to use in the given context and returns an object that rolls the HttpContext object back to its original state. 13 | /// 14 | /// An object that needs to be explicitly disposed so that HttpContext can return back to its original state. 15 | public static IDisposable EnsureSafeHttpContext() { 16 | HttpContext oldHttpContext = HttpContext.Current; 17 | HttpContext.Current = null; 18 | 19 | return new AnonymousDisposable(() => { 20 | HttpContext.Current = oldHttpContext; 21 | }); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/AnonymousDisposable.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading; 6 | using NLog; 7 | 8 | namespace ProjectExtensions.Azure.ServiceBus { 9 | 10 | internal sealed class AnonymousDisposable : IDisposable { 11 | 12 | static Logger logger = LogManager.GetCurrentClassLogger(); 13 | 14 | readonly Action dispose; 15 | int isDisposed; 16 | 17 | public AnonymousDisposable(Action dispose) { 18 | this.dispose = dispose; 19 | } 20 | 21 | public void Dispose() { 22 | logger.Debug("Dispose start"); 23 | if (Interlocked.Exchange(ref this.isDisposed, 1) == 0) { 24 | logger.Debug("Dispose this.isDisposed start"); 25 | this.dispose(); 26 | logger.Debug("Dispose this.isDisposed end"); 27 | } 28 | logger.Debug("Dispose end"); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/Interfaces/IAzureBusSender.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using ProjectExtensions.Azure.ServiceBus.Serialization; 3 | using System.Collections.Generic; 4 | 5 | namespace ProjectExtensions.Azure.ServiceBus.Interfaces { 6 | 7 | interface IAzureBusSender { 8 | void Close(); 9 | void Dispose(bool disposing); 10 | void Send(T obj); 11 | void Send(T obj, IDictionary metadata = null); 12 | void Send(T obj, IServiceBusSerializer serializer = null, IDictionary metadata = null); 13 | void SendAsync(T obj, object state, Action> resultCallBack); 14 | void SendAsync(T obj, object state, Action> resultCallBack, IDictionary metadata = null); 15 | void SendAsync(T obj, object state, Action> resultCallBack, IServiceBusSerializer serializer = null, IDictionary metadata = null); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus.StructureMap/Container/StructureMapBusConfigurationBuilderExtensions.cs: -------------------------------------------------------------------------------- 1 | using StructureMap; 2 | 3 | namespace ProjectExtensions.Azure.ServiceBus.StructureMap.Container { 4 | /// 5 | /// Extensions to allow configuration using Castle Windsor. 6 | /// 7 | public static class StructureMapBusConfigurationBuilderExtensions { 8 | /// 9 | /// Initializes Structure Map 10 | /// 11 | /// 12 | /// Structure Map container used in your application. This is optional. A new container will be created if one is not provided 13 | /// 14 | public static BusConfigurationBuilder UseStructureMapContainer(this BusConfigurationBuilder builder, IContainer container = null) { 15 | builder.Configuration.Container = new StructureMapAzureBusContainer(container); 16 | return builder; 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/Tests/ProjectExtensions.Azure.ServiceBus.Tests.Unit/Mocks/MockIAsyncResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading; 6 | 7 | namespace ProjectExtensions.Azure.ServiceBus.Tests.Unit.Mocks { 8 | 9 | class MockIAsyncResult : IAsyncResult { 10 | 11 | WaitHandle handle = null; 12 | 13 | public object AsyncState { 14 | get; 15 | set; 16 | } 17 | 18 | public WaitHandle AsyncWaitHandle { 19 | get { 20 | if (handle == null) { 21 | handle = new ManualResetEvent(false); 22 | } 23 | return handle; 24 | } 25 | } 26 | 27 | public bool CompletedSynchronously { 28 | get { 29 | return false; 30 | } 31 | } 32 | 33 | public bool IsCompleted { 34 | get { 35 | return false; 36 | } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/CommonAssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.34209 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | using System; 12 | using System.Reflection; 13 | using System.Resources; 14 | using System.Runtime.CompilerServices; 15 | using System.Runtime.InteropServices; 16 | 17 | [assembly: ComVisible(false)] 18 | [assembly: AssemblyVersion("0.10.7.0")] 19 | [assembly: AssemblyFileVersion("0.10.7.0")] 20 | [assembly: AssemblyCopyright("Copyright (C) Extensions.io 2015")] 21 | [assembly: AssemblyConfiguration("Debug")] 22 | [assembly: AssemblyCompany("Extensions.io")] 23 | [assembly: AssemblyProduct("Windows Azure Service Bus Wrapper modeled after the NServiceBus pattern of IHandl" + 24 | "eMessages (Debug DB: 0)")] 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/IReceivedMessage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | //DO NOT Change the namespace. 7 | namespace ProjectExtensions.Azure.ServiceBus { 8 | 9 | /// 10 | /// Main interface that is passed to the Handlers. 11 | /// 12 | /// 13 | public interface IReceivedMessage { 14 | 15 | /// 16 | /// A wrapped instance of the BrokeredMessage received from the Service Bus 17 | /// 18 | IBrokeredMessage BrokeredMessage { 19 | get; 20 | } 21 | 22 | /// 23 | /// The message that was sent. 24 | /// 25 | T Message { 26 | get; 27 | } 28 | 29 | /// 30 | /// The metadata passed with the message from the user. 31 | /// 32 | IDictionary Metadata { 33 | get; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus.Ninject/Container/NinjectBusConfigurationBuilderExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Ninject; 6 | 7 | namespace ProjectExtensions.Azure.ServiceBus.Ninject.Container { 8 | /// 9 | /// Extensions to allow use of the Ninject IoC container. 10 | /// 11 | public static class NinjectBusConfigurationBuilderExtensions { 12 | /// 13 | /// Initializes Autofac 14 | /// 15 | /// 16 | /// Ninject kernel used in your application. This is optional. A new kernel will be created if one is not provided 17 | /// 18 | public static BusConfigurationBuilder UseNinjectContainer(this BusConfigurationBuilder builder, IKernel container = null) { 19 | builder.Configuration.Container = new NinjectAzureBusContainer(container); 20 | return builder; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus.CastleWindsor/Container/CastleWindsorBusConfigurationBuilderExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Castle.Windsor; 6 | 7 | namespace ProjectExtensions.Azure.ServiceBus.CastleWindsor.Container { 8 | /// 9 | /// Extensions to allow configuration using Castle Windsor. 10 | /// 11 | public static class CastleWindsorBusConfigurationBuilderExtensions { 12 | /// 13 | /// Initializes Castle Windsor 14 | /// 15 | /// 16 | /// Castle Windsor container used in your application. This is optional. A new container will be created if one is not provided 17 | /// 18 | public static BusConfigurationBuilder UseCastleWindsorContainer(this BusConfigurationBuilder builder, IWindsorContainer container = null) { 19 | builder.Configuration.Container = new CastleWindsorBusContainer(container); 20 | return builder; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus.Unity/Container/UnityBusConfigurationBuilderExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Microsoft.Practices.Unity; 6 | using ProjectExtensions.Azure.ServiceBus; 7 | using ProjectExtensions.Azure.ServiceBus.Unity.Container; 8 | 9 | namespace ProjectExtensions.Azure.ServiceBus.Unity.Container { 10 | /// 11 | /// Extensions to allow configuration to use the Unity IoC container. 12 | /// 13 | public static class UnityBusConfigurationBuilderExtensions { 14 | /// 15 | /// Initializes Unity 16 | /// 17 | /// 18 | /// Unity container used in your application. This is optional. A new container will be created if one is not provided 19 | /// 20 | public static BusConfigurationBuilder UseUnityContainer(this BusConfigurationBuilder builder, IUnityContainer container = null) { 21 | builder.Configuration.Container = new UnityAzureBusContainer(container); 22 | return builder; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/TransientFaultHandling/ServiceBus/ServiceBusTransientErrorToDetermineExistanceDetectionStrategy.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling.ServiceBus; 6 | using System.Net; 7 | using Microsoft.ServiceBus.Messaging; 8 | 9 | namespace ProjectExtensions.Azure.ServiceBus.TransientFaultHandling.ServiceBus { 10 | 11 | /// 12 | /// When we verify if an item exits, we consider a 404 to NOT be Transient. 13 | /// 14 | class ServiceBusTransientErrorToDetermineExistanceDetectionStrategy : ServiceBusTransientErrorDetectionStrategy { 15 | 16 | protected override bool CheckIsTransientInternal(Exception ex) { 17 | 18 | if (ex is MessagingEntityNotFoundException) { 19 | return false; 20 | } 21 | else if (ex is WebException) { 22 | if (ex.Message.IndexOf("404") > -1) { 23 | return false; 24 | } 25 | } 26 | 27 | return base.CheckIsTransientInternal(ex); 28 | } 29 | 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/IMessageSentResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | //DO NOT Change the namespace. 4 | namespace ProjectExtensions.Azure.ServiceBus { 5 | 6 | /// 7 | /// Result of a call to SendAsyc on the message bus 8 | /// 9 | /// 10 | public interface IMessageSentResult { 11 | /// 12 | /// Did the message get sent successfully? 13 | /// 14 | bool IsSuccess { 15 | get; 16 | set; 17 | } 18 | 19 | /// 20 | /// The Exception thrown during the processing of sending the message. 21 | /// 22 | Exception ThrownException { 23 | get; 24 | set; 25 | } 26 | 27 | /// 28 | /// The actual time spent in milliseconds to send the message. 29 | /// 30 | TimeSpan TimeSpent { 31 | get; 32 | set; 33 | } 34 | 35 | /// 36 | /// A custom state object passed by the user. 37 | /// 38 | object State { 39 | get; 40 | set; 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /packages/repositories.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/Wrappers/TopicClientWrapper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using ProjectExtensions.Azure.ServiceBus.Interfaces; 6 | using Microsoft.ServiceBus.Messaging; 7 | using Microsoft.Practices.TransientFaultHandling; 8 | 9 | namespace ProjectExtensions.Azure.ServiceBus.Wrappers { 10 | 11 | class TopicClientWrapper : ITopicClient { 12 | 13 | TopicClient topicClient; 14 | 15 | public TopicClientWrapper(TopicClient topicClient) { 16 | Guard.ArgumentNotNull(topicClient, "topicClient"); 17 | this.topicClient = topicClient; 18 | } 19 | 20 | public IAsyncResult BeginSend(IBrokeredMessage message, AsyncCallback callback, object state) { 21 | if (!(message is BrokeredMessageWrapper)) { 22 | throw new ArgumentOutOfRangeException("message", "message must be BrokeredMessage for Azure use"); 23 | } 24 | return topicClient.BeginSend((message as BrokeredMessageWrapper).GetMessage(), callback, state); 25 | } 26 | 27 | public void EndSend(IAsyncResult result) { 28 | topicClient.EndSend(result); 29 | } 30 | 31 | public void Close() { 32 | topicClient.Close(); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Samples/PubSubUsingConfiguration/TestMessageSubscriber.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using ProjectExtensions.Azure.ServiceBus; 6 | using NLog; 7 | 8 | namespace PubSubUsingConfiguration { 9 | 10 | [MessageHandlerConfiguration( 11 | DeadLetterAfterMaxRetries=true, 12 | MaxRetries = 2, 13 | PauseTimeIfErrorWasThrown = 15000, 14 | Singleton = true)] 15 | public class TestMessageSubscriber : IHandleMessages { 16 | 17 | static Logger logger = LogManager.GetCurrentClassLogger(); 18 | 19 | public void Handle(IReceivedMessage message) { 20 | logger.Info("TestMessageSubscriber Message received: {0} {1}", message.Message.Value, message.Message.MessageId); 21 | //throw new Exception("I hate this message"); 22 | } 23 | } 24 | 25 | [MessageHandlerConfiguration( 26 | Singleton = true)] 27 | public class TestMessageSubscriberNumber2 : IHandleMessages { 28 | 29 | static Logger logger = LogManager.GetCurrentClassLogger(); 30 | 31 | public void Handle(IReceivedMessage message) { 32 | logger.Info("TestMessageSubscriberNumber2 Message received: {0} {1}", message.Message.Value, message.Message.MessageId); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/Factories/GenericServiceBusConfigurationFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using ProjectExtensions.Azure.ServiceBus.Interfaces; 6 | using Microsoft.Practices.TransientFaultHandling; 7 | using Microsoft.ServiceBus; 8 | using Microsoft.ServiceBus.Messaging; 9 | 10 | namespace ProjectExtensions.Azure.ServiceBus.Factories { 11 | 12 | class GenericServiceBusConfigurationFactory : IServiceBusConfigurationFactory { 13 | 14 | IBusConfiguration configuration; 15 | 16 | public GenericServiceBusConfigurationFactory(IBusConfiguration configuration, IMessagingFactory messageFactory, INamespaceManager namespaceManager) { 17 | Guard.ArgumentNotNull(configuration, "configuration"); 18 | Guard.ArgumentNotNull(messageFactory, "messageFactory"); 19 | Guard.ArgumentNotNull(namespaceManager, "namespaceManager"); 20 | this.configuration = configuration; 21 | this.MessageFactory = messageFactory; 22 | this.NamespaceManager = namespaceManager; 23 | } 24 | 25 | public IMessagingFactory MessageFactory { 26 | get; 27 | private set; 28 | } 29 | 30 | public INamespaceManager NamespaceManager { 31 | get; 32 | private set; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/Samples/PubSubUsingConfiguration/AnotherTestMessageSubscriber.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using ProjectExtensions.Azure.ServiceBus; 6 | using NLog; 7 | using System.Diagnostics; 8 | using Microsoft.ServiceBus.Messaging; 9 | 10 | namespace PubSubUsingConfiguration { 11 | 12 | [MessageHandlerConfiguration( 13 | DefaultMessageTimeToLive = 240, 14 | LockDuration = 120, 15 | MaxConcurrentCalls = 4, 16 | MaxRetries = 2, 17 | PrefetchCount = 20, 18 | PauseTimeIfErrorWasThrown = 20000, 19 | ReceiveMode = ReceiveMode.PeekLock, 20 | Singleton=true)] 21 | public class AnotherTestMessageSubscriber : IHandleCompetingMessages { 22 | 23 | static Logger logger = LogManager.GetCurrentClassLogger(); 24 | 25 | static bool timerSet = false; 26 | 27 | static Stopwatch sw = new Stopwatch(); 28 | 29 | public void Handle(IReceivedMessage message) { 30 | if (!timerSet) { 31 | sw.Start(); 32 | timerSet = true; 33 | } 34 | 35 | logger.Info("AnotherTestMessageSubscriber Message received: {0} {1} {2}", message.Message.Value, message.Message.MessageId, sw.ElapsedMilliseconds); 36 | throw new Exception("Bad Day"); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/Receiver/ReceivedMessage.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Microsoft.ServiceBus.Messaging; 6 | using Microsoft.Practices.TransientFaultHandling; 7 | 8 | namespace ProjectExtensions.Azure.ServiceBus.Receiver { 9 | 10 | class ReceivedMessage : IReceivedMessage { 11 | 12 | IBrokeredMessage brokeredMessage; 13 | T message; 14 | IDictionary metadata; 15 | 16 | public ReceivedMessage(IBrokeredMessage brokeredMessage, T message, IDictionary metadata) { 17 | Guard.ArgumentNotNull(brokeredMessage, "brokeredMessage"); 18 | Guard.ArgumentNotNull(message, "message"); 19 | Guard.ArgumentNotNull(metadata, "metadata"); 20 | this.brokeredMessage = brokeredMessage; 21 | this.message = message; 22 | this.metadata = metadata; 23 | } 24 | 25 | public IBrokeredMessage BrokeredMessage { 26 | get { 27 | return brokeredMessage; 28 | } 29 | } 30 | 31 | public T Message { 32 | get { 33 | return this.message; 34 | } 35 | } 36 | 37 | public IDictionary Metadata { 38 | get { 39 | return metadata; 40 | } 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/Serialization/IServiceBusSerializer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.IO; 6 | 7 | namespace ProjectExtensions.Azure.ServiceBus.Serialization { 8 | 9 | /// 10 | /// Interface that must be implemented to register a custom serializer 11 | /// 12 | public interface IServiceBusSerializer : IDisposable { 13 | 14 | /// 15 | /// Create an instance of the serializer 16 | /// 17 | /// 18 | IServiceBusSerializer Create(); 19 | 20 | /// 21 | /// Serialize the message 22 | /// 23 | /// 24 | /// 25 | Stream Serialize(object obj); 26 | 27 | /// 28 | /// Deserialize the message 29 | /// 30 | /// 31 | /// 32 | /// 33 | object Deserialize(Stream stream, Type type); 34 | 35 | /// 36 | /// Deserialize the message 37 | /// 38 | /// 39 | /// 40 | /// 41 | T Deserialize(Stream stream); 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/TransientFaultHandling.Core/ITransientErrorDetectionStrategy.cs: -------------------------------------------------------------------------------- 1 | //=============================================================================== 2 | // Microsoft patterns & practices Enterprise Library 3 | // Transient Fault Handling Application Block 4 | //=============================================================================== 5 | // Copyright © Microsoft Corporation. All rights reserved. 6 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY 7 | // OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT 8 | // LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 9 | // FITNESS FOR A PARTICULAR PURPOSE. 10 | //=============================================================================== 11 | 12 | namespace Microsoft.Practices.TransientFaultHandling 13 | { 14 | #region Using statements 15 | using System; 16 | #endregion 17 | 18 | /// 19 | /// Defines an interface which must be implemented by custom components responsible for detecting specific transient conditions. 20 | /// 21 | public interface ITransientErrorDetectionStrategy 22 | { 23 | /// 24 | /// Determines whether the specified exception represents a transient failure that can be compensated by a retry. 25 | /// 26 | /// The exception object to be verified. 27 | /// True if the specified exception is considered as transient, otherwise false. 28 | bool IsTransient(Exception ex); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/Tests/ProjectExtensions.Azure.ServiceBus.Tests.Unit/Mocks/MockMessagingFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using ProjectExtensions.Azure.ServiceBus.Interfaces; 6 | using Microsoft.ServiceBus.Messaging; 7 | using System.IO; 8 | using ProjectExtensions.Azure.ServiceBus.Tests.Unit.Interfaces; 9 | using Microsoft.Practices.TransientFaultHandling; 10 | 11 | namespace ProjectExtensions.Azure.ServiceBus.Tests.Unit.Mocks { 12 | 13 | class MockMessagingFactory : IMessagingFactory { 14 | 15 | IMockServiceBus serviceBus; 16 | 17 | public MockMessagingFactory(IBus serviceBus) { 18 | Guard.ArgumentNotNull(serviceBus, "serviceBus"); 19 | this.serviceBus = serviceBus as IMockServiceBus; 20 | Guard.ArgumentNotNull(this.serviceBus, "serviceBus"); 21 | } 22 | 23 | public ISubscriptionClient CreateSubscriptionClient(string topicPath, string name, ReceiveMode receiveMode) { 24 | return serviceBus.CreateSubscriptionClient(topicPath, name, receiveMode); 25 | } 26 | 27 | public ITopicClient CreateTopicClient(string path) { 28 | return serviceBus.CreateTopicClient(path); 29 | } 30 | 31 | public void Close() { 32 | 33 | } 34 | 35 | public IBrokeredMessage CreateBrokeredMessage(Stream messageBodyStream) { 36 | var retVal = new MockBrokeredMessage(serviceBus); 37 | retVal.SetBody(messageBodyStream); 38 | return retVal; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /license.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2011, Project Extensions and Joseph E. Feser 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of the nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 16 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL Project Extensions or Joseph E. Feser BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/Serialization/ServiceBusSerializerBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.IO; 6 | 7 | namespace ProjectExtensions.Azure.ServiceBus.Serialization { 8 | 9 | /// 10 | /// Abstract base class that may be used as a base class for serializers 11 | /// 12 | public abstract class ServiceBusSerializerBase : IServiceBusSerializer { 13 | 14 | /// 15 | /// Create an instance of the serializer 16 | /// 17 | /// 18 | public abstract IServiceBusSerializer Create(); 19 | 20 | /// 21 | /// Serialize the message 22 | /// 23 | /// 24 | /// 25 | public abstract Stream Serialize(object obj); 26 | 27 | /// 28 | /// Deserialize the message 29 | /// 30 | /// 31 | /// 32 | /// 33 | public abstract object Deserialize(Stream stream, Type type); 34 | 35 | /// 36 | /// Deserialize the message 37 | /// 38 | /// 39 | /// 40 | /// 41 | public T Deserialize(Stream stream) { 42 | return (T)Deserialize(stream, typeof(T)); 43 | } 44 | 45 | /// 46 | /// Dispose 47 | /// 48 | public abstract void Dispose(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Tests/ProjectExtensions.Azure.ServiceBus.Tests.Unit/Interfaces/IMockServiceBus.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Microsoft.ServiceBus.Messaging; 6 | using ProjectExtensions.Azure.ServiceBus.Interfaces; 7 | 8 | namespace ProjectExtensions.Azure.ServiceBus.Tests.Unit.Interfaces { 9 | 10 | interface IMockServiceBus : IBus { 11 | 12 | SubscriptionDescription CreateSubscription(SubscriptionDescription description, Filter filter); 13 | 14 | ISubscriptionClient CreateSubscriptionClient(string topicPath, string name, ReceiveMode receiveMode); 15 | 16 | ITopicClient CreateTopicClient(string path); 17 | 18 | TopicDescription CreateTopic(TopicDescription description); 19 | 20 | void DeleteSubscription(string topicPath, string name); 21 | 22 | SubscriptionDescription GetSubscription(string topicPath, string name); 23 | 24 | TopicDescription GetTopic(string path); 25 | 26 | void MessageAbandon(IBrokeredMessage message); 27 | 28 | void MessageComplete(IBrokeredMessage message); 29 | 30 | void MessageDeadLetter(IBrokeredMessage message, string deadLetterReason, string deadLetterErrorDescription); 31 | 32 | bool SubscriptionExists(string topicPath, string name); 33 | 34 | /// 35 | /// send a message and let the receivers get a copy of the message. 36 | /// 37 | /// 38 | void SendMessage(IBrokeredMessage message); 39 | 40 | IAsyncResult BeginReceive(ISubscriptionClient client, TimeSpan serverWaitTime, AsyncCallback callback, object state); 41 | 42 | IBrokeredMessage EndReceive(IAsyncResult result); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/AzureServiceBusFactories/ServiceBusTokenProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using ProjectExtensions.Azure.ServiceBus.Interfaces; 6 | using Microsoft.ServiceBus; 7 | using Microsoft.Practices.TransientFaultHandling; 8 | 9 | namespace ProjectExtensions.Azure.ServiceBus.AzureServiceBusFactories { 10 | 11 | class ServiceBusTokenProvider : IServiceBusTokenProvider { 12 | 13 | IBusConfiguration configuration; 14 | string servicePath; 15 | Uri serviceUri; 16 | TokenProvider tokenProvider; 17 | 18 | public ServiceBusTokenProvider(IBusConfiguration configuration) { 19 | Guard.ArgumentNotNull(configuration, "configuration"); 20 | 21 | this.configuration = configuration; 22 | servicePath = string.Empty; 23 | if (!string.IsNullOrWhiteSpace(configuration.ServicePath)) { 24 | servicePath = configuration.ServicePath; 25 | } 26 | } 27 | 28 | public TokenProvider TokenProvider { 29 | get { 30 | if (tokenProvider == null) { 31 | tokenProvider = TokenProvider.CreateSharedAccessSignatureTokenProvider(configuration.ServiceBusIssuerName, configuration.ServiceBusIssuerKey); 32 | } 33 | return tokenProvider; 34 | } 35 | } 36 | 37 | public Uri ServiceUri { 38 | get { 39 | if (serviceUri == null) { 40 | serviceUri = ServiceBusEnvironment.CreateServiceUri("sb", configuration.ServiceBusNamespace, servicePath); 41 | } 42 | return serviceUri; 43 | } 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/AzureServiceBusFactories/ServiceBusMessagingFactoryFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using ProjectExtensions.Azure.ServiceBus.Interfaces; 6 | using Microsoft.ServiceBus.Messaging; 7 | using Microsoft.Practices.TransientFaultHandling; 8 | using Microsoft.ServiceBus; 9 | using ProjectExtensions.Azure.ServiceBus.Wrappers; 10 | using System.IO; 11 | using NLog; 12 | 13 | namespace ProjectExtensions.Azure.ServiceBus.AzureServiceBusFactories { 14 | 15 | class ServiceBusMessagingFactoryFactory : IMessagingFactory { 16 | 17 | static Logger logger = LogManager.GetCurrentClassLogger(); 18 | MessagingFactory messagingFactory; 19 | 20 | public ServiceBusMessagingFactoryFactory(IServiceBusTokenProvider tokenProvider) { 21 | Guard.ArgumentNotNull(tokenProvider, "tokenProvider"); 22 | messagingFactory = MessagingFactory.Create(tokenProvider.ServiceUri, tokenProvider.TokenProvider); 23 | } 24 | 25 | public ISubscriptionClient CreateSubscriptionClient(string topicPath, string name, ReceiveMode receiveMode) { 26 | return new SubscriptionClientWrapper(messagingFactory.CreateSubscriptionClient(topicPath, name, receiveMode)); 27 | } 28 | 29 | public ITopicClient CreateTopicClient(string path) { 30 | return new TopicClientWrapper(messagingFactory.CreateTopicClient(path)); 31 | } 32 | 33 | public void Close() { 34 | messagingFactory.Close(); 35 | } 36 | 37 | public IBrokeredMessage CreateBrokeredMessage(Stream messageBodyStream) { 38 | return new BrokeredMessageWrapper(new BrokeredMessage(messageBodyStream, false)); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Tests/ProjectExtensions.Azure.ServiceBus.Tests.Unit/Mocks/MockNamespaceManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using ProjectExtensions.Azure.ServiceBus.Interfaces; 6 | using Microsoft.ServiceBus.Messaging; 7 | using ProjectExtensions.Azure.ServiceBus.Tests.Unit.Interfaces; 8 | using Microsoft.Practices.TransientFaultHandling; 9 | 10 | namespace ProjectExtensions.Azure.ServiceBus.Tests.Unit.Mocks { 11 | 12 | class MockNamespaceManager : INamespaceManager { 13 | 14 | IMockServiceBus serviceBus; 15 | 16 | public MockNamespaceManager(IBus serviceBus) { 17 | Guard.ArgumentNotNull(serviceBus, "serviceBus"); 18 | this.serviceBus = serviceBus as IMockServiceBus; 19 | Guard.ArgumentNotNull(this.serviceBus, "serviceBus"); 20 | } 21 | 22 | public SubscriptionDescription CreateSubscription(SubscriptionDescription description, Filter filter) { 23 | return serviceBus.CreateSubscription(description, filter); 24 | } 25 | 26 | public TopicDescription CreateTopic(TopicDescription description) { 27 | return serviceBus.CreateTopic(description); 28 | } 29 | 30 | public void DeleteSubscription(string topicPath, string name) { 31 | serviceBus.DeleteSubscription(topicPath, name); 32 | } 33 | 34 | public SubscriptionDescription GetSubscription(string topicPath, string name) { 35 | return serviceBus.GetSubscription(topicPath, name); 36 | } 37 | 38 | public TopicDescription GetTopic(string path) { 39 | return serviceBus.GetTopic(path); 40 | } 41 | 42 | public bool SubscriptionExists(string topicPath, string name) { 43 | return serviceBus.SubscriptionExists(topicPath, name); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Samples/PubSubUsingConfiguration/Bootstrapper.cs: -------------------------------------------------------------------------------- 1 | using System.Configuration; 2 | using Amazon.ServiceBus.DistributedMessages.Serializers; 3 | using ProjectExtensions.Azure.ServiceBus; 4 | using ProjectExtensions.Azure.ServiceBus.Autofac.Container; 5 | 6 | namespace PubSubUsingConfiguration { 7 | static internal class Bootstrapper { 8 | public static void Initialize() { 9 | 10 | var setup = new ServiceBusSetupConfiguration() { 11 | DefaultSerializer = new GZipXmlSerializer(), 12 | ServiceBusIssuerKey = ConfigurationManager.AppSettings["ServiceBusIssuerKey"], 13 | ServiceBusIssuerName = ConfigurationManager.AppSettings["ServiceBusIssuerName"], 14 | ServiceBusNamespace = ConfigurationManager.AppSettings["ServiceBusNamespace"], 15 | ServiceBusApplicationId = "AppName" 16 | }; 17 | 18 | setup.AssembliesToRegister.Add(typeof(TestMessageSubscriber).Assembly); 19 | 20 | BusConfiguration.WithSettings() 21 | .UseAutofacContainer() 22 | .ReadFromConfigurationSettings(setup) 23 | //.EnablePartitioning(true) 24 | .DefaultSerializer(new GZipXmlSerializer()) 25 | .Configure(); 26 | 27 | /* 28 | BusConfiguration.WithSettings() 29 | .UseAutofacContainer() 30 | .ReadFromConfigFile() 31 | .ServiceBusApplicationId("AppName") 32 | .DefaultSerializer(new GZipXmlSerializer()) 33 | //.ServiceBusIssuerKey("[sb password]") 34 | //.ServiceBusIssuerName("owner") 35 | //.ServiceBusNamespace("[addresshere]") 36 | .RegisterAssembly(typeof(TestMessageSubscriber).Assembly) 37 | .Configure(); 38 | */ 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /src/Tests/ProjectExtensions.Azure.ServiceBus.Tests.Unit/Mocks/MockTopicClient.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using ProjectExtensions.Azure.ServiceBus.Interfaces; 6 | using ProjectExtensions.Azure.ServiceBus.Tests.Unit.Interfaces; 7 | using Microsoft.Practices.TransientFaultHandling; 8 | 9 | namespace ProjectExtensions.Azure.ServiceBus.Tests.Unit.Mocks { 10 | 11 | class MockTopicClient : ITopicClient { 12 | 13 | IDictionary _messages = new Dictionary(); 14 | 15 | IMockServiceBus serviceBus; 16 | 17 | public string Path { 18 | get; 19 | private set; 20 | } 21 | 22 | public MockTopicClient(IBus serviceBus, string path) { 23 | Guard.ArgumentNotNull(serviceBus, "serviceBus"); 24 | this.serviceBus = serviceBus as IMockServiceBus; 25 | Guard.ArgumentNotNull(this.serviceBus, "serviceBus"); 26 | this.Path = path; 27 | } 28 | 29 | public IAsyncResult BeginSend(IBrokeredMessage message, AsyncCallback callback, object state) { 30 | var retVal = new MockIAsyncResult() { 31 | AsyncState = state 32 | }; 33 | _messages[retVal] = message; 34 | callback(retVal); 35 | return retVal; 36 | } 37 | 38 | public void EndSend(IAsyncResult result) { 39 | IBrokeredMessage message = null; 40 | if (!_messages.TryGetValue(result, out message)) { 41 | throw new ApplicationException("You must call EndSend with a valid IAsyncResult. Duplicate Calls are not allowed."); 42 | } 43 | serviceBus.SendMessage(message); 44 | } 45 | 46 | public void Close() { 47 | //do nothing 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /tools/MSBuild/BuildSupport/Common.targets.properties: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | [ExampleCompanyName] 7 | [ExampleProductName] 8 | [Example Description] 9 | 10 | 11 | 12 | 13 | Debug 14 | false 15 | 16 | 17 | 18 | 19 | 0.1.0 20 | 0 21 | 22 | 23 | 24 | 25 | false 26 | false 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | false 38 | 39 | 40 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /ProjectExtensions.Azure.ServiceBus.IOC.Unity.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ProjectExtensions.Azure.ServiceBus.IOC.Unity 5 | Unity Support for Windows Azure Service Bus Message Wrapper using the NServiceBus IHandleMessages<T> Pattern 6 | 0.10.7.0 7 | Extensions.io, Joe Feser 8 | Extensions.io, Joe Feser 9 | Copyright (c) Extensions.io and Joe Feser 2014 10 | https://github.com/ProjectExtensions/ProjectExtensions.Azure.ServiceBus 11 | false 12 | Unity support for Windows Azure Service Bus wrapper modeled after the NServiceBus pattern of IHandleMessages<T> 13 | Unity support for Windows Azure Service Bus Wrapper modeled after the NServiceBus pattern of IHandleMessages<T>. You will 14 | also need ProjectExtensions.Azure.ServiceBus.Core. (Debug) 15 | 16 | 17 | 18 | ServiceBus Microsoft Azure AppFabric Messaging PubSub Publish Subscribe Queue Topic 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /ProjectExtensions.Azure.ServiceBus.IOC.Autofac.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ProjectExtensions.Azure.ServiceBus.IOC.Autofac 5 | Autofac Support for Windows Azure Service Bus Message Wrapper using the NServiceBus IHandleMessages<T> Pattern 6 | 0.10.7.0 7 | Extensions.io, Joe Feser 8 | Extensions.io, Joe Feser 9 | Copyright (c) Extensions.io and Joe Feser 2014 10 | https://github.com/ProjectExtensions/ProjectExtensions.Azure.ServiceBus 11 | false 12 | Autofac support for Windows Azure Service Bus wrapper modeled after the NServiceBus pattern of IHandleMessages<T> 13 | Autofac support for Windows Azure Service Bus Wrapper modeled after the NServiceBus pattern of IHandleMessages<T>. You will 14 | also need ProjectExtensions.Azure.ServiceBus.Core. (Debug) 15 | 16 | 17 | 18 | ServiceBus Microsoft Azure AppFabric Messaging PubSub Publish Subscribe Queue Topic 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /ProjectExtensions.Azure.ServiceBus.IOC.Ninject.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ProjectExtensions.Azure.ServiceBus.IOC.Ninject 5 | Ninject Support for Windows Azure Service Bus Message Wrapper using the NServiceBus IHandleMessages<T> Pattern 6 | 0.10.7.0 7 | Extensions.io, Joe Feser 8 | Extensions.io, Joe Feser 9 | Copyright (c) Extensions.io and Joe Feser 2014 10 | https://github.com/ProjectExtensions/ProjectExtensions.Azure.ServiceBus 11 | false 12 | Ninject support for Windows Azure Service Bus wrapper modeled after the NServiceBus pattern of IHandleMessages<T> 13 | Ninject support for Windows Azure Service Bus Wrapper modeled after the NServiceBus pattern of IHandleMessages<T>. You will 14 | also need ProjectExtensions.Azure.ServiceBus.Core. (Debug) 15 | 16 | 17 | 18 | ServiceBus Microsoft Azure AppFabric Messaging PubSub Publish Subscribe Queue Topic 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/Interfaces/IServiceBusSetupConfiguration.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Text; 6 | using ProjectExtensions.Azure.ServiceBus.Serialization; 7 | 8 | namespace ProjectExtensions.Azure.ServiceBus.Interfaces { 9 | 10 | /// 11 | /// Interface used to define the settings we can pull from the user instead of them being hard coded in the web/app.config file or passed in as parameters. 12 | /// 13 | public interface IServiceBusSetupConfiguration { 14 | 15 | /// 16 | /// Set the DefaultSerializer 17 | /// 18 | IServiceBusSerializer DefaultSerializer { get; } 19 | 20 | /// 21 | /// Auto discover all of the Subscribers in the assembly. 22 | /// 23 | List AssembliesToRegister { get; } 24 | 25 | /// 26 | /// Register subscriber by type 27 | /// 28 | List TypesToRegister { get; } 29 | 30 | /// 31 | /// ServiceBusApplicationId 32 | /// 33 | string ServiceBusApplicationId { get; } 34 | 35 | /// 36 | /// ServiceBusNamespace (required) 37 | /// 38 | string ServiceBusNamespace { get; } 39 | 40 | /// 41 | /// ServiceBusIssuerName (required) 42 | /// 43 | string ServiceBusIssuerName { get; } 44 | 45 | /// 46 | /// ServiceBusIssuerKey (required) 47 | /// 48 | string ServiceBusIssuerKey { get; } 49 | 50 | /// 51 | /// ServicePath 52 | /// 53 | string ServicePath { get; } 54 | 55 | /// 56 | /// TopicName 57 | /// 58 | string TopicName { get; } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/IMessageHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | //DO NOT Change the namespace. 7 | namespace ProjectExtensions.Azure.ServiceBus { 8 | 9 | /// 10 | /// Basic message Handler 11 | /// 12 | /// The type of message to be handled. 13 | /// A new handler will be instantiated for each message unless you decorate your handler class with [SingletonMessageHandler] 14 | public interface IMessageHandler { 15 | /// 16 | /// Process a Message with the given signature. 17 | /// 18 | /// The message to handle. 19 | /// 20 | /// Every message received by the bus with this message type will call this method. 21 | /// 22 | void Handle(IReceivedMessage message); 23 | 24 | } 25 | 26 | /// 27 | /// Interface that needs to be implemented if you wish to register a subscription. 28 | /// 29 | /// 30 | /// A new handler will be instantiated for each message unless you decorate your handler class with [SingletonMessageHandler] 31 | public interface IHandleMessages : IMessageHandler { 32 | 33 | } 34 | 35 | /// 36 | /// Interface that needs to be implemented if you wish to register a competing subscription. 37 | /// 38 | /// This implementation will allow the Topic to scale out, allowing multiple subscibers to handle the messages sent. 39 | /// 40 | /// A new handler will be instantiated for each message unless you decorate your handler class with [SingletonMessageHandler] 41 | public interface IHandleCompetingMessages : IMessageHandler { 42 | 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/Receiver/AzureBusReceiverState.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading; 6 | using Microsoft.ServiceBus.Messaging; 7 | using ProjectExtensions.Azure.ServiceBus.Interfaces; 8 | 9 | namespace ProjectExtensions.Azure.ServiceBus.Receiver { 10 | /// 11 | /// Class used to store everything needed in the state and also used so we can cancel. 12 | /// 13 | class AzureBusReceiverState { 14 | 15 | CancellationTokenSource cancelToken = new CancellationTokenSource(); 16 | 17 | public CancellationTokenSource CancelToken { 18 | get { 19 | return cancelToken; 20 | } 21 | } 22 | 23 | /// 24 | /// Once the item has stopped running, it marks the state as cancelled. 25 | /// 26 | public bool Cancelled { 27 | get { 28 | return CancelToken.IsCancellationRequested && MessageLoopCompleted; 29 | } 30 | } 31 | 32 | public ISubscriptionClient Client { 33 | get; 34 | set; 35 | } 36 | 37 | public ServiceBusEnpointData EndPointData { 38 | get; 39 | set; 40 | } 41 | 42 | /// 43 | /// when a message loop is complete, this is called so things can be cleaned up. 44 | /// 45 | public bool MessageLoopCompleted { 46 | get; 47 | private set; 48 | } 49 | 50 | public void Cancel() { 51 | // Stop the message receive loop gracefully. 52 | cancelToken.Cancel(); 53 | } 54 | 55 | /// 56 | /// Called when receive returnes from completing a message loop. 57 | /// 58 | public void SetMessageLoopCompleted() { 59 | MessageLoopCompleted = true; 60 | } 61 | 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/Receiver/AzureReceiveState.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Reflection; 6 | using Microsoft.ServiceBus.Messaging; 7 | using ProjectExtensions.Azure.ServiceBus.Serialization; 8 | using Microsoft.Practices.TransientFaultHandling; 9 | 10 | namespace ProjectExtensions.Azure.ServiceBus.Receiver { 11 | 12 | class AzureReceiveState { 13 | 14 | public AzureReceiveState(AzureBusReceiverState data, MethodInfo methodInfo, 15 | IServiceBusSerializer serializer, IBrokeredMessage message) { 16 | Guard.ArgumentNotNull(data, "data"); 17 | Guard.ArgumentNotNull(methodInfo, "methodInfo"); 18 | Guard.ArgumentNotNull(serializer, "serializer"); 19 | Guard.ArgumentNotNull(message, "message"); 20 | this.Data = data; 21 | this.MethodInfo = methodInfo; 22 | this.Serializer = serializer; 23 | this.Message = message; 24 | } 25 | 26 | public AzureBusReceiverState Data { 27 | get; 28 | set; 29 | } 30 | public MethodInfo MethodInfo { 31 | get; 32 | set; 33 | } 34 | private IServiceBusSerializer Serializer { 35 | get; 36 | set; 37 | } 38 | public IBrokeredMessage Message { 39 | get; 40 | set; 41 | } 42 | 43 | public IServiceBusSerializer CreateSerializer() { 44 | return Serializer.Create(); 45 | } 46 | /* 47 | 48 | //TODO create a cache for object creation. 49 | var gt = typeof(IReceivedMessage<>).MakeGenericType(data.EndPointData.MessageType); 50 | 51 | //set up the methodinfo 52 | var methodInfo = data.EndPointData.DeclaredType.GetMethod("Handle", 53 | new Type[] { gt, typeof(IDictionary) }); 54 | 55 | */ 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /ProjectExtensions.Azure.ServiceBus.IOC.StructureMap.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ProjectExtensions.Azure.ServiceBus.IOC.StructureMap 5 | StructureMap Support for Windows Azure Service Bus Message Wrapper using the NServiceBus IHandleMessages<T> Pattern 6 | 0.10.7.0 7 | Extensions.io, Joe Feser 8 | Extensions.io, Joe Feser 9 | Copyright (c) Extensions.io and Joe Feser 2014 10 | https://github.com/ProjectExtensions/ProjectExtensions.Azure.ServiceBus 11 | false 12 | StructureMap support for Windows Azure Service Bus wrapper modeled after the NServiceBus pattern of IHandleMessages<T> 13 | StructureMap support for Windows Azure Service Bus Wrapper modeled after the NServiceBus pattern of IHandleMessages<T>. You will 14 | also need ProjectExtensions.Azure.ServiceBus.Core. (Debug) 15 | 16 | 17 | 18 | ServiceBus Microsoft Azure AppFabric Messaging PubSub Publish Subscribe Queue Topic 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/AzureServiceBusFactories/ServiceBusNamespaceManagerFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using ProjectExtensions.Azure.ServiceBus.Interfaces; 6 | using Microsoft.ServiceBus.Messaging; 7 | using Microsoft.ServiceBus; 8 | using Microsoft.Practices.TransientFaultHandling; 9 | using NLog; 10 | 11 | namespace ProjectExtensions.Azure.ServiceBus.AzureServiceBusFactories { 12 | 13 | class ServiceBusNamespaceManagerFactory : INamespaceManager { 14 | 15 | static Logger logger = LogManager.GetCurrentClassLogger(); 16 | 17 | NamespaceManager namespaceManager; 18 | 19 | public ServiceBusNamespaceManagerFactory(IServiceBusTokenProvider tokenProvider) { 20 | Guard.ArgumentNotNull(tokenProvider, "tokenProvider"); 21 | namespaceManager = new NamespaceManager(tokenProvider.ServiceUri, tokenProvider.TokenProvider); 22 | } 23 | 24 | public SubscriptionDescription CreateSubscription(SubscriptionDescription description, Filter filter) { 25 | return namespaceManager.CreateSubscription(description, filter); 26 | } 27 | 28 | public TopicDescription CreateTopic(TopicDescription description) { 29 | return namespaceManager.CreateTopic(description); 30 | } 31 | 32 | public void DeleteSubscription(string topicPath, string name) { 33 | namespaceManager.DeleteSubscription(topicPath, name); 34 | } 35 | 36 | public SubscriptionDescription GetSubscription(string topicPath, string name) { 37 | return namespaceManager.GetSubscription(topicPath, name); 38 | } 39 | 40 | public TopicDescription GetTopic(string path) { 41 | return namespaceManager.GetTopic(path); 42 | } 43 | 44 | public bool SubscriptionExists(string topicPath, string name) { 45 | return namespaceManager.SubscriptionExists(topicPath, name); 46 | } 47 | 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /ProjectExtensions.Azure.ServiceBus.IOC.CastleWindsor.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ProjectExtensions.Azure.ServiceBus.IOC.CastleWindsor 5 | Castle Windsor Support for Windows Azure Service Bus Message Wrapper using the NServiceBus IHandleMessages<T> Pattern 6 | 0.10.7.0 7 | Extensions.io, Joe Feser 8 | Extensions.io, Joe Feser 9 | Copyright (c) Extensions.io and Joe Feser 2014 10 | https://github.com/ProjectExtensions/ProjectExtensions.Azure.ServiceBus 11 | false 12 | Castle Windsor support for Windows Azure Service Bus wrapper modeled after the NServiceBus pattern of IHandleMessages<T> 13 | Castle Windsor support for Windows Azure Service Bus Wrapper modeled after the NServiceBus pattern of IHandleMessages<T>. You will 14 | also need ProjectExtensions.Azure.ServiceBus.Core. (Debug) 15 | 16 | 17 | 18 | ServiceBus Microsoft Azure AppFabric Messaging PubSub Publish Subscribe Queue Topic 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/Wrappers/SubscriptionClientWrapper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using ProjectExtensions.Azure.ServiceBus.Interfaces; 6 | using Microsoft.ServiceBus.Messaging; 7 | using Microsoft.Practices.TransientFaultHandling; 8 | 9 | namespace ProjectExtensions.Azure.ServiceBus.Wrappers { 10 | 11 | class SubscriptionClientWrapper : ISubscriptionClient { 12 | 13 | SubscriptionClient client; 14 | 15 | public SubscriptionClientWrapper(SubscriptionClient client) { 16 | Guard.ArgumentNotNull(client, "client"); 17 | this.client = client; 18 | } 19 | 20 | public bool IsClosed { 21 | get { 22 | return client.IsClosed; 23 | } 24 | } 25 | 26 | public ReceiveMode Mode { 27 | get { 28 | return client.Mode; 29 | } 30 | } 31 | 32 | public int PrefetchCount { 33 | get { 34 | return client.PrefetchCount; 35 | } 36 | set { 37 | client.PrefetchCount = value; 38 | } 39 | } 40 | 41 | public IAsyncResult BeginReceive(TimeSpan serverWaitTime, AsyncCallback callback, object state) { 42 | return client.BeginReceive(serverWaitTime, callback, state); 43 | } 44 | 45 | public IBrokeredMessage EndReceive(IAsyncResult result) { 46 | var msg = client.EndReceive(result); 47 | if (msg != null) { 48 | return new BrokeredMessageWrapper(msg); 49 | } 50 | return null; 51 | } 52 | 53 | public void OnMessage(Action callback, OnMessageOptions onMessageOptions) { 54 | client.OnMessage((msg) => { 55 | callback(new BrokeredMessageWrapper(msg)); 56 | }, onMessageOptions); 57 | } 58 | 59 | public void Close() { 60 | client.Close(); 61 | } 62 | 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/Helpers/ReflectionHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Reflection; 6 | using System.Linq.Expressions; 7 | 8 | namespace ProjectExtensions.Azure.ServiceBus.Helpers { 9 | 10 | //http://rogeralsing.com/2008/02/28/linq-expressions-creating-objects/ 11 | 12 | delegate object ObjectActivator(params object[] args); 13 | 14 | static class ReflectionHelper { 15 | 16 | internal static ObjectActivator GetActivator(ConstructorInfo ctor) { 17 | Type type = ctor.DeclaringType; 18 | ParameterInfo[] paramsInfo = ctor.GetParameters(); 19 | 20 | //create a single param of type object[] 21 | ParameterExpression param = 22 | Expression.Parameter(typeof(object[]), "args"); 23 | 24 | Expression[] argsExp = 25 | new Expression[paramsInfo.Length]; 26 | 27 | //pick each arg from the params array 28 | //and create a typed expression of them 29 | for (int i = 0; i < paramsInfo.Length; i++) { 30 | Expression index = Expression.Constant(i); 31 | Type paramType = paramsInfo[i].ParameterType; 32 | 33 | Expression paramAccessorExp = 34 | Expression.ArrayIndex(param, index); 35 | 36 | Expression paramCastExp = 37 | Expression.Convert(paramAccessorExp, paramType); 38 | 39 | argsExp[i] = paramCastExp; 40 | } 41 | 42 | //make a NewExpression that calls the 43 | //ctor with the args we just created 44 | NewExpression newExp = Expression.New(ctor, argsExp); 45 | 46 | //create a lambda with the New 47 | //Expression as body and our param object[] as arg 48 | LambdaExpression lambda = 49 | Expression.Lambda(typeof(ObjectActivator), newExp, param); 50 | 51 | //compile it 52 | ObjectActivator compiled = (ObjectActivator)lambda.Compile(); 53 | return compiled; 54 | } 55 | 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/Tests/ProjectExtensions.Azure.ServiceBus.Tests.Unit/Mocks/MockSubscriptionClient.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using ProjectExtensions.Azure.ServiceBus.Interfaces; 6 | using ProjectExtensions.Azure.ServiceBus.Tests.Unit.Interfaces; 7 | using Microsoft.ServiceBus.Messaging; 8 | using Microsoft.Practices.TransientFaultHandling; 9 | 10 | namespace ProjectExtensions.Azure.ServiceBus.Tests.Unit.Mocks { 11 | 12 | class MockSubscriptionClient : ISubscriptionClient { 13 | 14 | IMockServiceBus serviceBus; 15 | string topicPath; 16 | string name; 17 | ReceiveMode receiveMode; 18 | 19 | public MockSubscriptionClient(IBus serviceBus, string topicPath, string name, ReceiveMode receiveMode) { 20 | Guard.ArgumentNotNull(serviceBus, "serviceBus"); 21 | Guard.ArgumentNotNull(topicPath, "topicPath"); 22 | Guard.ArgumentNotNull(name, "name"); 23 | this.serviceBus = serviceBus as IMockServiceBus; 24 | Guard.ArgumentNotNull(this.serviceBus, "serviceBus"); 25 | this.topicPath = topicPath; 26 | this.name = name; 27 | this.receiveMode = receiveMode; 28 | } 29 | 30 | public bool IsClosed { 31 | get; 32 | set; 33 | } 34 | 35 | public int PrefetchCount { 36 | get; 37 | set; 38 | } 39 | 40 | public IAsyncResult BeginReceive(TimeSpan serverWaitTime, AsyncCallback callback, object state) { 41 | return serviceBus.BeginReceive(this, serverWaitTime, callback, state); 42 | } 43 | 44 | public IBrokeredMessage EndReceive(IAsyncResult result) { 45 | return serviceBus.EndReceive(result); 46 | } 47 | 48 | public void OnMessage(Action callback, OnMessageOptions onMessageOptions) { 49 | throw new NotImplementedException(); 50 | } 51 | 52 | public void Close() { 53 | 54 | } 55 | 56 | public ReceiveMode Mode { 57 | get { 58 | return receiveMode; 59 | } 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/Samples/PubSubUsingConfiguration/GZipXmlSerializer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using ProjectExtensions.Azure.ServiceBus.Serialization; 6 | using NLog; 7 | using System.IO; 8 | using System.Xml.Serialization; 9 | using System.IO.Compression; 10 | using System.Xml; 11 | 12 | namespace Amazon.ServiceBus.DistributedMessages.Serializers { 13 | 14 | public class GZipXmlSerializer : ServiceBusSerializerBase { 15 | 16 | static Logger logger = LogManager.GetCurrentClassLogger(); 17 | MemoryStream serializedStream; 18 | 19 | public override IServiceBusSerializer Create() { 20 | return new GZipXmlSerializer(); 21 | } 22 | 23 | public override Stream Serialize(object obj) { 24 | var serial = new XmlSerializer(obj.GetType()); 25 | serializedStream = new MemoryStream(); 26 | 27 | using (var zipStream = new GZipStream(serializedStream, CompressionMode.Compress, true)) { 28 | using (var writer = XmlDictionaryWriter.CreateBinaryWriter(zipStream, null, null, false)) { 29 | serial.Serialize(writer, obj); 30 | } 31 | } 32 | 33 | serializedStream.Position = 0; //make sure you always set the stream position to where you want to serialize. 34 | logger.Debug("Serialize {0} at Bytes={1}", obj.GetType(), serializedStream.Length); 35 | return serializedStream; 36 | } 37 | 38 | public override object Deserialize(Stream stream, Type type) { 39 | var serial = new XmlSerializer(type); 40 | logger.Debug("Deserialize {0} at {1} bytes", type, stream.Length); 41 | using (var zipStream = new GZipStream(stream, CompressionMode.Decompress, true)) { 42 | using (var reader = XmlDictionaryReader.CreateBinaryReader(zipStream, XmlDictionaryReaderQuotas.Max)) { 43 | return serial.Deserialize(reader); 44 | } 45 | } 46 | } 47 | 48 | public override void Dispose() { 49 | if (serializedStream != null) { 50 | serializedStream.Dispose(); 51 | serializedStream = null; 52 | } 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/Tests/ProjectExtensions.Azure.ServiceBus.Tests.Unit/Config.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using NUnit.Framework; 6 | using ProjectExtensions.Azure.ServiceBus.Autofac.Container; 7 | using Autofac; 8 | using ProjectExtensions.Azure.ServiceBus.Interfaces; 9 | using ProjectExtensions.Azure.ServiceBus.Tests.Unit.Mocks; 10 | using ProjectExtensions.Azure.ServiceBus.Tests.Unit.Messages; 11 | using ProjectExtensions.Azure.ServiceBus.Tests.Unit.Interfaces; 12 | using System.Diagnostics; 13 | 14 | namespace ProjectExtensions.Azure.ServiceBus.Tests.Unit { 15 | 16 | [SetUpFixture] 17 | public class Config { 18 | 19 | [SetUp] 20 | public void SetUp() { 21 | 22 | var builder = new ContainerBuilder(); 23 | 24 | builder.RegisterType(typeof(MockSubscriptionClient)).As(typeof(ISubscriptionClient)).SingleInstance(); 25 | builder.RegisterType(typeof(MockTopicClient)).As(typeof(ITopicClient)).SingleInstance(); 26 | builder.RegisterType(typeof(MockNamespaceManager)).As(typeof(INamespaceManager)).SingleInstance(); 27 | builder.RegisterType(typeof(MockMessagingFactory)).As(typeof(IMessagingFactory)).SingleInstance(); 28 | builder.RegisterType(typeof(MockServiceBus)).As(typeof(IBus)).SingleInstance(); 29 | 30 | BusConfiguration.WithSettings() 31 | .UseAutofacContainer(builder.Build()) 32 | .ServiceBusApplicationId("AppName") 33 | .TopicName("test") 34 | .RegisterAssembly(typeof(Config).Assembly) 35 | .Configure(); 36 | 37 | //test send a message 38 | 39 | for (int i = 0; i < 10; i++) { 40 | BusConfiguration.Instance.Bus.PublishAsync(new TestMessageForTesting(), (callback) => { 41 | Debug.WriteLine("Time Spent:" + callback.TimeSpent); 42 | Console.WriteLine("Time Spent:" + callback.TimeSpent); 43 | }); 44 | } 45 | } 46 | 47 | [TearDown] 48 | public void TearDown() { 49 | 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/Container/IAzureBusContainer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using ProjectExtensions.Azure.ServiceBus.Serialization; 6 | 7 | namespace ProjectExtensions.Azure.ServiceBus.Container { 8 | /// 9 | /// Generic IOC container interface 10 | /// 11 | public interface IAzureBusContainer { 12 | /// 13 | /// Resolve component type of T. 14 | /// 15 | /// 16 | /// 17 | T Resolve() where T : class; 18 | /// 19 | /// Resolve component. 20 | /// 21 | /// The type to resolve 22 | /// 23 | object Resolve(Type t); 24 | /// 25 | /// Register an implementation for a service type. 26 | /// 27 | /// The service type. 28 | /// The implementation type. 29 | /// True creates an instance each time resolved. False uses a singleton instance for the entire lifetime of the process. 30 | void Register(Type serviceType, Type implementationType, bool perInstance = false); 31 | 32 | /// 33 | /// Registers the configuration instance with the bus if it is not already registered 34 | /// 35 | void RegisterConfiguration(); 36 | /// 37 | /// Build the container if needed. 38 | /// 39 | void Build(); 40 | /// 41 | /// Return true if the given type is registered with the container. 42 | /// 43 | /// 44 | /// 45 | bool IsRegistered(Type type); 46 | 47 | /// 48 | /// Return the Service Bus 49 | /// 50 | IBus Bus { 51 | get; 52 | } 53 | 54 | /// 55 | /// Resolve the Default Serializer 56 | /// 57 | IServiceBusSerializer DefaultSerializer { 58 | get; 59 | } 60 | 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/TransientFaultHandling/ExtensionMethods.cs: -------------------------------------------------------------------------------- 1 | //=============================================================================== 2 | // Microsoft patterns & practices Enterprise Library 3 | // Transient Fault Handling Application Block 4 | //=============================================================================== 5 | // Copyright © Microsoft Corporation. All rights reserved. 6 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY 7 | // OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT 8 | // LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 9 | // FITNESS FOR A PARTICULAR PURPOSE. 10 | //=============================================================================== 11 | 12 | namespace Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling 13 | { 14 | #region Using statements 15 | using System; 16 | #endregion 17 | 18 | /// 19 | /// Provides a set of extension methods that supplement various .NET Framework classes with value-add functionality. 20 | /// 21 | public static class ExtensionMethods 22 | { 23 | /// 24 | /// Verifies whether the specified exception object contains an inner exception of the specified type . 25 | /// 26 | /// The type of the inner exception to look for. 27 | /// The exception object to be inspected. 28 | /// The instance of the inner exception of the specified type if found, otherwise null. 29 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1004:GenericMethodsShouldProvideTypeParameter", Justification = "As designed")] 30 | public static Exception GetInnerException(this Exception ex) 31 | { 32 | var innerEx = ex != null ? ex.InnerException : null; 33 | var exceptionType = typeof(T); 34 | 35 | while (innerEx != null) 36 | { 37 | if (exceptionType.IsAssignableFrom(innerEx.GetType())) 38 | { 39 | return innerEx; 40 | } 41 | 42 | innerEx = innerEx.InnerException; 43 | } 44 | 45 | return null; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /ProjectExtensions.Azure.ServiceBus.Core.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ProjectExtensions.Azure.ServiceBus.Core 5 | Windows Azure Service Bus Message Wrapper using the NServiceBus IHandleMessages<T> Pattern (Core) 6 | 0.10.7.0 7 | Extensions.io, Joe Feser 8 | Extensions.io, Joe Feser 9 | Copyright (c) Extensions.io and Joe Feser 2014 10 | https://github.com/ProjectExtensions/ProjectExtensions.Azure.ServiceBus 11 | false 12 | Added support for the EnablePartitioning Setting for a Topic. Added MaxConcurrentCalls Support. This will spin up multiple instances of your receiver, increasing performance. 13 | Windows Azure Service Bus wrapper modeled after the NServiceBus pattern of IHandleMessage<T>. (Core) 14 | Windows Azure Service Bus Wrapper modeled after the NServiceBus pattern of IHandleMessages<T>. Does not include IoC container support implementation. 15 | Either create your own implementation of IAzureBusContainer or get one of the IoC packages (ProjectExtensions.Azure.ServiceBus.IOC.[container]) 16 | where container is Autofac, CastleWindsor, Ninject, StructureMap or Unity. (Debug) 17 | 18 | 19 | 20 | 21 | 22 | ServiceBus Microsoft Azure AppFabric Messaging PubSub Publish Subscribe Queue Topic 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/TransientFaultHandling.Core/RetryingEventArgs.cs: -------------------------------------------------------------------------------- 1 | //=============================================================================== 2 | // Microsoft patterns & practices Enterprise Library 3 | // Transient Fault Handling Application Block 4 | //=============================================================================== 5 | // Copyright © Microsoft Corporation. All rights reserved. 6 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY 7 | // OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT 8 | // LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 9 | // FITNESS FOR A PARTICULAR PURPOSE. 10 | //=============================================================================== 11 | 12 | namespace Microsoft.Practices.TransientFaultHandling 13 | { 14 | using System; 15 | 16 | /// 17 | /// Contains information required for the event. 18 | /// 19 | public class RetryingEventArgs : EventArgs 20 | { 21 | /// 22 | /// Initializes a new instance of the class. 23 | /// 24 | /// The current retry attempt count. 25 | /// The delay indicating how long the current thread will be suspended for before the next iteration will be invoked. 26 | /// The exception which caused the retry conditions to occur. 27 | public RetryingEventArgs(int currentRetryCount, TimeSpan delay, Exception lastException) 28 | { 29 | Guard.ArgumentNotNull(lastException, "lastException"); 30 | 31 | this.CurrentRetryCount = currentRetryCount; 32 | this.Delay = delay; 33 | this.LastException = lastException; 34 | } 35 | 36 | /// 37 | /// Gets the current retry count. 38 | /// 39 | public int CurrentRetryCount { get; private set; } 40 | 41 | /// 42 | /// Gets the delay indicating how long the current thread will be suspended for before the next iteration will be invoked. 43 | /// 44 | public TimeSpan Delay { get; private set; } 45 | 46 | /// 47 | /// Gets the exception which caused the retry conditions to occur. 48 | /// 49 | public Exception LastException { get; private set; } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/TransientFaultHandling/AzureStorage/AzureStorageExtensions.cs: -------------------------------------------------------------------------------- 1 | //=============================================================================== 2 | // Microsoft patterns & practices Enterprise Library 3 | // Transient Fault Handling Application Block 4 | //=============================================================================== 5 | // Copyright © Microsoft Corporation. All rights reserved. 6 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY 7 | // OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT 8 | // LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 9 | // FITNESS FOR A PARTICULAR PURPOSE. 10 | //=============================================================================== 11 | 12 | namespace Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling.AzureStorage 13 | { 14 | using Microsoft.Practices.TransientFaultHandling; 15 | 16 | /// 17 | /// Extends the RetryStrategy to allow using the retry strategies from the Transient Fault Handling Application Block with Windows Azure Store. 18 | /// 19 | public static class AzureStorageExtensions 20 | { 21 | /// 22 | /// Wrap a Transient Fault Handling Application Block retry strategy into a Microsoft.WindowsAzure.StorageClient.RetryPolicy. 23 | /// 24 | /// The Transient Fault Handling Application Block retry strategy to wrap. 25 | /// Returns a wrapped Transient Fault Handling Application Block retry strategy into a Microsoft.WindowsAzure.StorageClient.RetryPolicy. 26 | public static Microsoft.WindowsAzure.StorageClient.RetryPolicy AsAzureStorageClientRetryPolicy(this RetryStrategy retryStrategy) 27 | { 28 | Guard.ArgumentNotNull(retryStrategy, "retryStrategy"); 29 | 30 | return () => new ShouldRetryWrapper(retryStrategy.GetShouldRetry()).ShouldRetry; 31 | } 32 | 33 | private class ShouldRetryWrapper 34 | { 35 | private readonly ShouldRetry shouldRetry; 36 | 37 | public ShouldRetryWrapper(ShouldRetry shouldRetry) 38 | { 39 | this.shouldRetry = shouldRetry; 40 | } 41 | 42 | public bool ShouldRetry(int retryCount, System.Exception lastException, out System.TimeSpan delay) 43 | { 44 | return this.shouldRetry(retryCount, lastException, out delay); 45 | } 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/ServiceBusEnpointData.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Reflection; 6 | using ProjectExtensions.Azure.ServiceBus.Helpers; 7 | using ProjectExtensions.Azure.ServiceBus.Receiver; 8 | 9 | namespace ProjectExtensions.Azure.ServiceBus { 10 | 11 | class ServiceBusEnpointData { 12 | 13 | string _subscriptionNameDebug; 14 | 15 | /// 16 | /// Custom attribute found on the class. 17 | /// 18 | public MessageHandlerConfigurationAttribute AttributeData { 19 | get; 20 | set; 21 | } 22 | 23 | /// 24 | /// The type containing the interface 25 | /// 26 | public Type DeclaredType { 27 | get; 28 | set; 29 | } 30 | 31 | public Type ServiceType { 32 | get; 33 | set; 34 | } 35 | 36 | public string SubscriptionName { 37 | get; 38 | set; 39 | } 40 | 41 | public string SubscriptionNameDebug { 42 | get { 43 | if (_subscriptionNameDebug == null) { 44 | _subscriptionNameDebug = DeclaredType.FullName.Replace("`1", "") + "<" + MessageType.FullName + "> - " + SubscriptionName; 45 | } 46 | return _subscriptionNameDebug; 47 | } 48 | } 49 | 50 | /// 51 | /// If true, it is a singleton 52 | /// 53 | public bool IsReusable { 54 | get { 55 | return AttributeData != null && AttributeData.Singleton; 56 | } 57 | } 58 | 59 | /// 60 | /// The message type 61 | /// 62 | public Type MessageType { 63 | get; 64 | set; 65 | } 66 | 67 | ObjectActivator activator = null; 68 | 69 | public object GetReceivedMessage(object[] obj) { 70 | if (activator == null) { 71 | var genericType = typeof(ReceivedMessage<>).MakeGenericType(MessageType); 72 | //object receivedMessage = Activator.CreateInstance(gt, new object[] { state.Message, msg, values }); 73 | ConstructorInfo ctor = genericType.GetConstructors().First(); 74 | activator = ReflectionHelper.GetActivator(ctor); 75 | } 76 | //create an instance: 77 | return activator(obj); 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/Container/AzureBusContainerBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using ProjectExtensions.Azure.ServiceBus.Serialization; 6 | 7 | namespace ProjectExtensions.Azure.ServiceBus.Container { 8 | 9 | /// 10 | /// Base class for all Containers. 11 | /// 12 | public abstract class AzureBusContainerBase : IAzureBusContainer { 13 | 14 | /// 15 | /// Resolve component type of T. 16 | /// 17 | /// 18 | /// 19 | public abstract T Resolve() where T : class; 20 | 21 | /// 22 | /// Resolve component. 23 | /// 24 | /// The type to resolve 25 | /// 26 | public abstract object Resolve(Type t); 27 | 28 | /// 29 | /// Register an implementation for a service type. 30 | /// 31 | /// The service type. 32 | /// The implementation type. 33 | /// True creates an instance each time resolved. False uses a singleton instance for the entire lifetime of the process. 34 | public abstract void Register(Type serviceType, Type implementationType, bool perInstance = false); 35 | 36 | /// 37 | /// Registers the configuration instance with the bus if it is not already registered 38 | /// 39 | public abstract void RegisterConfiguration(); 40 | 41 | /// 42 | /// Build the container if needed. 43 | /// 44 | public abstract void Build(); 45 | 46 | /// 47 | /// Return true if the given type is registered with the container. 48 | /// 49 | /// 50 | /// 51 | public abstract bool IsRegistered(Type type); 52 | 53 | /// 54 | /// Return the Service Bus 55 | /// 56 | public virtual IBus Bus { 57 | get { 58 | return Resolve(); 59 | } 60 | } 61 | 62 | /// 63 | /// Resolve the Default Serializer 64 | /// 65 | public virtual IServiceBusSerializer DefaultSerializer { 66 | get { 67 | return Resolve(); 68 | } 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/Serialization/XmlServiceBusSerializer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using NLog; 6 | using System.IO; 7 | using System.Xml.Serialization; 8 | using System.Xml; 9 | 10 | namespace ProjectExtensions.Azure.ServiceBus.Serialization { 11 | 12 | /// 13 | /// Default XmlSerializer that is used when serializing messages. 14 | /// 15 | public class XmlServiceBusSerializer : ServiceBusSerializerBase { 16 | 17 | static Logger logger = LogManager.GetCurrentClassLogger(); 18 | MemoryStream serializedStream; 19 | 20 | /// 21 | /// Create an instance of the serializer 22 | /// 23 | /// 24 | public override IServiceBusSerializer Create() { 25 | return new XmlServiceBusSerializer(); 26 | } 27 | 28 | /// 29 | /// Serialize the message 30 | /// 31 | /// 32 | /// 33 | public override Stream Serialize(object obj) { 34 | var serial = new XmlSerializer(obj.GetType()); 35 | serializedStream = new MemoryStream(); 36 | 37 | using (var writer = XmlDictionaryWriter.CreateBinaryWriter(serializedStream, null, null, false)) { 38 | serial.Serialize(writer, obj); 39 | } 40 | 41 | serializedStream.Position = 0; //make sure you always set the stream position to where you want to serialize. 42 | logger.Debug("Serialize {0} at Bytes={1}", obj.GetType(), serializedStream.Length); 43 | return serializedStream; 44 | } 45 | 46 | /// 47 | /// Deserialize the message 48 | /// 49 | /// 50 | /// 51 | /// 52 | public override object Deserialize(Stream stream, Type type) { 53 | var serial = new XmlSerializer(type); 54 | logger.Debug("Deserialize {0} at {1} bytes", type, stream.Length); 55 | using (var reader = XmlDictionaryReader.CreateBinaryReader(stream, XmlDictionaryReaderQuotas.Max)) { 56 | return serial.Deserialize(reader); 57 | } 58 | } 59 | 60 | /// 61 | /// Dispose 62 | /// 63 | public override void Dispose() { 64 | if (serializedStream != null) { 65 | serializedStream.Dispose(); 66 | serializedStream = null; 67 | } 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/ServiceBusSetupConfiguration.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Text; 6 | using ProjectExtensions.Azure.ServiceBus.Interfaces; 7 | using ProjectExtensions.Azure.ServiceBus.Serialization; 8 | 9 | namespace ProjectExtensions.Azure.ServiceBus { 10 | 11 | /// 12 | /// ServiceBusSetupConfiguration (Default Implementation) 13 | /// 14 | public class ServiceBusSetupConfiguration : IServiceBusSetupConfiguration { 15 | 16 | /// 17 | /// new ServiceBusSetupConfiguration 18 | /// 19 | public ServiceBusSetupConfiguration() { 20 | AssembliesToRegister = new List(); 21 | TypesToRegister = new List(); 22 | } 23 | 24 | /// 25 | /// Set the DefaultSerializer 26 | /// 27 | public IServiceBusSerializer DefaultSerializer { 28 | get; 29 | set; 30 | } 31 | 32 | /// 33 | /// Auto discover all of the Subscribers in the assembly. 34 | /// 35 | public List AssembliesToRegister { 36 | get; 37 | private set; 38 | } 39 | 40 | /// 41 | /// Register subscriber by type 42 | /// 43 | public List TypesToRegister { 44 | get; 45 | private set; 46 | } 47 | 48 | /// 49 | /// ServiceBusApplicationId 50 | /// 51 | public string ServiceBusApplicationId { 52 | get; 53 | set; 54 | } 55 | 56 | /// 57 | /// ServiceBusNamespace (required) 58 | /// 59 | public string ServiceBusNamespace { 60 | get; 61 | set; 62 | } 63 | 64 | /// 65 | /// ServiceBusIssuerName (required) 66 | /// 67 | public string ServiceBusIssuerName { 68 | get; 69 | set; 70 | } 71 | 72 | /// 73 | /// ServiceBusIssuerKey (required) 74 | /// 75 | public string ServiceBusIssuerKey { 76 | get; 77 | set; 78 | } 79 | 80 | /// 81 | /// ServicePath 82 | /// 83 | public string ServicePath { 84 | get; 85 | set; 86 | } 87 | 88 | /// 89 | /// TopicName 90 | /// 91 | public string TopicName { 92 | get; 93 | set; 94 | } 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /ProjectExtensions.Azure.ServiceBus.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ProjectExtensions.Azure.ServiceBus 5 | Windows Azure Service Bus Message Wrapper using the NServiceBus IHandleMessages<T> Pattern 6 | 0.10.7.0 7 | Extensions.io, Joe Feser 8 | Extensions.io, Joe Feser 9 | Copyright (c) Extensions.io and Joe Feser 2014 10 | https://github.com/ProjectExtensions/ProjectExtensions.Azure.ServiceBus 11 | false 12 | Breaking change. You must use SAS Authentication. CAS is no longer supported. 13 | Windows Azure Service Bus wrapper modeled after the NServiceBus pattern of IHandleMessages<T> 14 | Windows Azure Service Bus Wrapper modeled after the NServiceBus pattern of IHandleMessages<T>. Includes Autofac IoC container support. 15 | If you use a different IoC container, get ProjectExtensions.Azure.ServiceBus.Core and one of the IoC packages (ProjectExtensions.Azure.ServiceBus.IOC.[container]) 16 | where container is Autofac, CastleWindsor, StructureMap or Unity. (Debug) 17 | 18 | 19 | 20 | 21 | 22 | 23 | ServiceBus Microsoft Azure AppFabric Messaging PubSub Publish Subscribe Queue Topic 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/TransientFaultHandling/RetryPolicyException.cs: -------------------------------------------------------------------------------- 1 | //=============================================================================== 2 | // Microsoft patterns & practices Enterprise Library 3 | // Transient Fault Handling Application Block 4 | //=============================================================================== 5 | // Copyright © Microsoft Corporation. All rights reserved. 6 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY 7 | // OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT 8 | // LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 9 | // FITNESS FOR A PARTICULAR PURPOSE. 10 | //=============================================================================== 11 | 12 | namespace Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling 13 | { 14 | using System; 15 | using System.Runtime.Serialization; 16 | 17 | /// 18 | /// Represents an error that occurs while using the Transient Fault Handling Application Block. 19 | /// 20 | [Serializable] 21 | public class RetryPolicyException : Exception 22 | { 23 | /// 24 | /// Initializes a new instance of the class. 25 | /// 26 | public RetryPolicyException() 27 | { 28 | } 29 | 30 | /// 31 | /// Initializes a new instance of the class with a specified error message. 32 | /// 33 | /// The message that describes the error. 34 | public RetryPolicyException(string message) 35 | : base(message) 36 | { 37 | } 38 | 39 | /// 40 | /// Initializes a new instance of the class with a specified error message 41 | /// and a reference to the inner exception that is the cause of this exception. 42 | /// 43 | /// The message that describes the error. 44 | /// The inner exception reference. 45 | public RetryPolicyException(string message, Exception inner) : base(message, inner) 46 | { 47 | } 48 | 49 | /// 50 | /// Initializes a new instance of the class with serialized data. 51 | /// 52 | /// The that holds the serialized object data about the exception being thrown. 53 | /// The that contains contextual information about the source or destination. 54 | protected RetryPolicyException( 55 | SerializationInfo info, 56 | StreamingContext context) : base(info, context) 57 | { 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/Serialization/JsonServiceBusSerializer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.IO; 6 | using Newtonsoft.Json; 7 | using NLog; 8 | 9 | namespace ProjectExtensions.Azure.ServiceBus.Serialization { 10 | 11 | /// 12 | /// JSon Serializer that may be used to serialize messages 13 | /// 14 | public class JsonServiceBusSerializer : ServiceBusSerializerBase { 15 | 16 | static Logger logger = LogManager.GetCurrentClassLogger(); 17 | Stream serializedStream; 18 | 19 | /// 20 | /// Create an instance of the serializer 21 | /// 22 | /// 23 | public override IServiceBusSerializer Create() { 24 | return new JsonServiceBusSerializer(); 25 | } 26 | 27 | /// 28 | /// Serialize the message 29 | /// 30 | /// 31 | /// 32 | public override Stream Serialize(object obj) { 33 | JsonSerializer serializer = new JsonSerializer(); 34 | serializer.NullValueHandling = NullValueHandling.Ignore; 35 | 36 | serializedStream = new MemoryStream(); 37 | 38 | StreamWriter sw = new StreamWriter(serializedStream); 39 | //do not wrap in using, we don't want to close the stream 40 | JsonWriter jw = new JsonTextWriter(sw); 41 | serializer.Serialize(jw, obj); 42 | jw.Flush(); 43 | serializedStream.Position = 0; //make sure you always set the stream position to where you want to serialize. 44 | 45 | logger.Debug("Serialize {0} at {1} bytes", obj.GetType(), serializedStream.Length); 46 | 47 | return serializedStream; 48 | } 49 | 50 | /// 51 | /// Deserialize the message 52 | /// 53 | /// 54 | /// 55 | /// 56 | public override object Deserialize(Stream stream, Type type) { 57 | logger.Debug("Deserialize {0} at {1} bytes", type, stream.Length); 58 | 59 | JsonSerializer serializer = new JsonSerializer(); 60 | //serializer.Converters.Add(new JavaScriptDateTimeConverter()); 61 | serializer.NullValueHandling = NullValueHandling.Ignore; 62 | 63 | StreamReader sr = new StreamReader(stream); 64 | //do not wrap in using, we don't want to close the stream 65 | var jr = new JsonTextReader(sr); 66 | return serializer.Deserialize(jr, type); 67 | } 68 | 69 | /// 70 | /// Dispose 71 | /// 72 | public override void Dispose() { 73 | if (serializedStream != null) { 74 | serializedStream.Dispose(); 75 | serializedStream = null; 76 | } 77 | } 78 | } 79 | } -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/Helpers/BusHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Microsoft.Practices.TransientFaultHandling; 6 | using NLog; 7 | 8 | namespace ProjectExtensions.Azure.ServiceBus.Helpers { 9 | 10 | /// 11 | /// Generic code in the bus that can be reused by the mocks 12 | /// 13 | internal static class BusHelper { 14 | 15 | internal static void SubscribeOrUnsubscribeType(Action logInfo, Type type, IBusConfiguration config, Action callback) { 16 | Guard.ArgumentNotNull(type, "type"); 17 | Guard.ArgumentNotNull(callback, "callback"); 18 | 19 | logInfo(string.Format("SubscribeOrUnsubscribeType={0}", type.FullName)); 20 | var interfaces = type.GetInterfaces() 21 | .Where(i => i.IsGenericType && (i.GetGenericTypeDefinition() == typeof(IHandleMessages<>) || i.GetGenericTypeDefinition() == typeof(IHandleCompetingMessages<>))) 22 | .ToList(); 23 | 24 | if (interfaces.Count == 0) { 25 | throw new ApplicationException(string.Format("Type {0} does not implement IHandleMessages or IHandleCompetingMessages", type.FullName)); 26 | } 27 | 28 | //for each interface we find, we need to register it with the bus. 29 | foreach (var foundInterface in interfaces) { 30 | 31 | var implementedMessageType = foundInterface.GetGenericArguments()[0]; 32 | //due to the limits of 50 chars we will take the name and a MD5 for the name. 33 | var hashName = implementedMessageType.FullName + "|" + type.FullName; 34 | 35 | var hash = MD5Helper.CalculateMD5(hashName); 36 | var fullName = (IsCompetingHandler(foundInterface) ? "C_" : config.ServiceBusApplicationId + "_") + hash; 37 | 38 | var info = new ServiceBusEnpointData() { 39 | AttributeData = type.GetCustomAttributes(typeof(MessageHandlerConfigurationAttribute), false).FirstOrDefault() as MessageHandlerConfigurationAttribute, 40 | DeclaredType = type, 41 | MessageType = implementedMessageType, 42 | SubscriptionName = fullName, 43 | ServiceType = foundInterface 44 | }; 45 | 46 | if (!config.Container.IsRegistered(type)) { 47 | if (info.IsReusable) { 48 | config.Container.Register(type, type); 49 | } 50 | else { 51 | config.Container.Register(type, type, true); 52 | } 53 | } 54 | 55 | callback(info); 56 | } 57 | 58 | config.Container.Build(); 59 | } 60 | 61 | static bool IsCompetingHandler(Type type) { 62 | return type.GetGenericTypeDefinition() == typeof(IHandleCompetingMessages<>); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/IBusConfiguration.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Reflection; 4 | using ProjectExtensions.Azure.ServiceBus.Container; 5 | using ProjectExtensions.Azure.ServiceBus.Serialization; 6 | 7 | //DO NOT Change the namespace. 8 | namespace ProjectExtensions.Azure.ServiceBus { 9 | 10 | /// 11 | /// Interface for the Bus Configuration 12 | /// 13 | public interface IBusConfiguration { 14 | 15 | /// 16 | /// The Service Bus 17 | /// 18 | IBus Bus { 19 | get; 20 | } 21 | 22 | /// 23 | /// DefaultSerializer 24 | /// 25 | IServiceBusSerializer DefaultSerializer { 26 | get; 27 | } 28 | 29 | /// 30 | /// Enable Partitioning on the Topic 31 | /// 32 | bool EnablePartitioning { 33 | get; 34 | } 35 | 36 | /// 37 | /// Max Threads to call the message handlers from the bus messages being received 38 | /// 39 | byte MaxThreads { 40 | get; 41 | } 42 | 43 | /// 44 | /// List of RegisteredAssemblies 45 | /// 46 | IList RegisteredAssemblies { 47 | get; 48 | } 49 | 50 | /// 51 | /// List of RegisteredSubscribers 52 | /// 53 | IList RegisteredSubscribers { 54 | get; 55 | } 56 | 57 | /// 58 | /// ServiceBusApplicationId 59 | /// 60 | string ServiceBusApplicationId { 61 | get; 62 | } 63 | 64 | /// 65 | /// ServiceBusNamespace 66 | /// 67 | string ServiceBusIssuerKey { 68 | get; 69 | } 70 | 71 | /// 72 | /// ServiceBusIssuerName 73 | /// 74 | string ServiceBusIssuerName { 75 | get; 76 | } 77 | 78 | /// 79 | /// ServiceBusIssuerKey 80 | /// 81 | string ServiceBusNamespace { 82 | get; 83 | } 84 | 85 | /// 86 | /// ServicePath 87 | /// 88 | string ServicePath { 89 | get; 90 | } 91 | 92 | /// 93 | /// TopicName 94 | /// 95 | string TopicName { 96 | get; 97 | } 98 | 99 | /// 100 | /// The IOC Container for the application 101 | /// 102 | /// The setter can only be called once. This is normally done via the builder. 103 | /// You should not call the setter directly. 104 | IAzureBusContainer Container { 105 | get; 106 | set; 107 | } 108 | 109 | /// 110 | /// Apply the configuration 111 | /// 112 | void Configure(); 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus.StructureMap/Container/StructureMapAzureBusContainer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using ProjectExtensions.Azure.ServiceBus.Container; 3 | using StructureMap; 4 | using StructureMap.Pipeline; 5 | 6 | namespace ProjectExtensions.Azure.ServiceBus.StructureMap.Container { 7 | /// 8 | /// Implementation of for Structure Map. 9 | /// 10 | public class StructureMapAzureBusContainer : AzureBusContainerBase { 11 | IContainer container; 12 | 13 | /// 14 | /// Constructor. 15 | /// 16 | /// Optional StructueMap container. If one is not provided, a new one will be created. 17 | public StructureMapAzureBusContainer(IContainer container = null) { 18 | this.container = container ?? new global::StructureMap.Container(); 19 | } 20 | /// 21 | /// Resolve component type of T with optional arguments. 22 | /// 23 | /// 24 | /// 25 | public override T Resolve() { 26 | return container.GetInstance(); 27 | } 28 | 29 | /// 30 | /// Resolve component with optional arguments. 31 | /// 32 | /// The type to resolve 33 | /// 34 | public override object Resolve(Type t) { 35 | return container.GetInstance(t); 36 | } 37 | 38 | /// 39 | /// Register an implementation for a service type. 40 | /// 41 | /// The service type. 42 | /// The implementation type. 43 | /// True creates an instance each time resolved. False uses a singleton instance for the entire lifetime of the process. 44 | public override void Register(Type serviceType, Type implementationType, bool perInstance = false) { 45 | ILifecycle lifecycle = perInstance ? (ILifecycle)new UniquePerRequestLifecycle() : (ILifecycle)new SingletonLifecycle(); 46 | container.Configure(c => c.For(serviceType).LifecycleIs(lifecycle).Use(implementationType)); 47 | } 48 | 49 | /// 50 | /// Registers the configuration instance with the bus if it is not already registered 51 | /// 52 | public override void RegisterConfiguration() { 53 | if (!IsRegistered(typeof(IBusConfiguration))) { 54 | container.Configure(c => c.For().LifecycleIs(new SingletonLifecycle()).Use(() => BusConfiguration.Instance)); 55 | } 56 | } 57 | 58 | /// 59 | /// Build the container if needed. 60 | /// 61 | public override void Build() { 62 | //do nothing 63 | } 64 | 65 | /// 66 | /// Return true if the given type is registered with the container. 67 | /// 68 | /// 69 | /// 70 | public override bool IsRegistered(Type type) { 71 | return container.Model.HasDefaultImplementationFor(type); 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus.Unity/Container/UnityAzureBusContainer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Microsoft.Practices.Unity; 6 | using ProjectExtensions.Azure.ServiceBus.Container; 7 | 8 | namespace ProjectExtensions.Azure.ServiceBus.Unity.Container { 9 | /// 10 | /// Implementation of for Unity. 11 | /// 12 | public class UnityAzureBusContainer : AzureBusContainerBase { 13 | IUnityContainer container; 14 | 15 | /// 16 | /// Constructor. 17 | /// 18 | /// Unity container used in your application. This is optional. A new container will be created if one is not provided. 19 | public UnityAzureBusContainer(IUnityContainer container = null) { 20 | this.container = container ?? new UnityContainer(); 21 | } 22 | /// 23 | /// Resolve component type of T with optional arguments. 24 | /// 25 | /// 26 | /// 27 | public override T Resolve() { 28 | return container.Resolve(); 29 | } 30 | 31 | /// 32 | /// Resolve component with optional arguments. 33 | /// 34 | /// The type to resolve 35 | /// 36 | public override object Resolve(Type t) { 37 | return container.Resolve(t); 38 | } 39 | 40 | /// 41 | /// Register an implementation for a service type. 42 | /// 43 | /// The service type. 44 | /// The implementation type. 45 | /// True creates an instance each time resolved. False uses a singleton instance for the entire lifetime of the process. 46 | public override void Register(Type serviceType, Type implementationType, bool perInstance = false) { 47 | if (perInstance) { 48 | container.RegisterType(serviceType, implementationType, new TransientLifetimeManager()); 49 | } 50 | else { 51 | container.RegisterType(serviceType, implementationType, new ContainerControlledLifetimeManager()); 52 | } 53 | } 54 | 55 | /// 56 | /// Registers the configuration instance with the bus if it is not already registered 57 | /// 58 | public override void RegisterConfiguration() { 59 | if (!IsRegistered(typeof(IBusConfiguration))) { 60 | container.RegisterInstance(BusConfiguration.Instance, new ContainerControlledLifetimeManager()); 61 | } 62 | } 63 | 64 | /// 65 | /// Build the container if needed. 66 | /// 67 | public override void Build() { 68 | //do nothing 69 | } 70 | 71 | /// 72 | /// Return true if the given type is registered with the container. 73 | /// 74 | /// 75 | /// 76 | public override bool IsRegistered(Type type) { 77 | return container.IsRegistered(type); 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus.Ninject/Container/NinjectAzureBusContainer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Ninject; 6 | using Ninject.Activation; 7 | using Ninject.Parameters; 8 | using ProjectExtensions.Azure.ServiceBus.Container; 9 | 10 | namespace ProjectExtensions.Azure.ServiceBus.Ninject.Container { 11 | 12 | /// 13 | /// Implementation of for Ninject. 14 | /// 15 | public class NinjectAzureBusContainer : AzureBusContainerBase { 16 | IKernel container; 17 | 18 | /// 19 | /// Constructor. 20 | /// 21 | /// Optional Ninject kernel owned by the calling application. 22 | /// If one is not provided, a new one will be created. 23 | public NinjectAzureBusContainer(IKernel container = null) { 24 | this.container = container ?? new StandardKernel(); 25 | } 26 | 27 | 28 | /// 29 | /// Resolve component type of T with optional arguments. 30 | /// 31 | /// 32 | /// 33 | public override T Resolve() { 34 | return container.Get(); 35 | } 36 | 37 | /// 38 | /// Resolve component with optional arguments. 39 | /// 40 | /// The type to resolve 41 | /// 42 | public override object Resolve(Type t) { 43 | return container.Get(t); 44 | } 45 | 46 | /// 47 | /// Register an implementation for a service type. 48 | /// 49 | /// The service type. 50 | /// The implementation type. 51 | /// True creates an instance each time resolved. False uses a singleton instance for the entire lifetime of the process. 52 | public override void Register(Type serviceType, Type implementationType, bool perInstance = false) { 53 | if (perInstance) { 54 | container.Bind(serviceType).To(implementationType).InTransientScope(); 55 | } 56 | else { 57 | container.Bind(serviceType).To(implementationType).InSingletonScope(); 58 | } 59 | } 60 | 61 | /// 62 | /// Registers the configuration instance with the bus if it is not already registered 63 | /// 64 | public override void RegisterConfiguration() { 65 | if (!IsRegistered(typeof(IBusConfiguration))) { 66 | container.Bind().ToConstant(BusConfiguration.Instance).InSingletonScope(); 67 | } 68 | } 69 | 70 | /// 71 | /// Build the container if needed. 72 | /// 73 | public override void Build() { 74 | //do nothing 75 | } 76 | 77 | /// 78 | /// Return true if the given type is registered with the container. 79 | /// 80 | /// 81 | /// 82 | public override bool IsRegistered(Type type) { 83 | return container.CanResolve(container.CreateRequest(type, null, new List(), false, false)); 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus.CastleWindsor/Container/CastleWindsorBusContainer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Castle.MicroKernel.Registration; 6 | using Castle.Windsor; 7 | using ProjectExtensions.Azure.ServiceBus.Container; 8 | 9 | namespace ProjectExtensions.Azure.ServiceBus.CastleWindsor.Container { 10 | /// 11 | /// Implementation of for Castle Windsor. 12 | /// 13 | public class CastleWindsorBusContainer : AzureBusContainerBase { 14 | IWindsorContainer container; 15 | 16 | /// 17 | /// Constructor. 18 | /// 19 | /// Optional Castle Windsor container. If one is not provided, 20 | /// a new one will be created. 21 | public CastleWindsorBusContainer(IWindsorContainer container = null) { 22 | this.container = container ?? new WindsorContainer(); 23 | } 24 | /// 25 | /// Resolve component type of T with optional arguments. 26 | /// 27 | /// 28 | /// 29 | public override T Resolve() { 30 | return container.Resolve(); 31 | } 32 | 33 | /// 34 | /// Resolve component with optional arguments. 35 | /// 36 | /// The type to resolve 37 | /// 38 | public override object Resolve(Type t) { 39 | return container.Resolve(t); 40 | } 41 | 42 | /// 43 | /// Register an implementation for a service type. 44 | /// 45 | /// The service type. 46 | /// The implementation type. 47 | /// True creates an instance each time resolved. False uses a singleton instance for the entire lifetime of the process. 48 | public override void Register(Type serviceType, Type implementationType, bool perInstance = false) { 49 | if (perInstance) { 50 | container.Register(Component.For(serviceType).ImplementedBy(implementationType).LifestyleTransient()); 51 | } else { 52 | container.Register(Component.For(serviceType).ImplementedBy(implementationType).LifestyleSingleton()); 53 | } 54 | } 55 | 56 | /// 57 | /// Registers the configuration instance with the bus if it is not already registered 58 | /// 59 | public override void RegisterConfiguration() { 60 | if (!IsRegistered(typeof(IBusConfiguration))) { 61 | container.Register(Component.For().Instance(BusConfiguration.Instance).LifestyleSingleton()); 62 | } 63 | } 64 | 65 | /// 66 | /// Build the container if needed. 67 | /// 68 | public override void Build() { 69 | //do nothing 70 | } 71 | 72 | /// 73 | /// Return true if the given type is registered with the container. 74 | /// 75 | /// 76 | /// 77 | public override bool IsRegistered(Type type) { 78 | return container.Kernel.HasComponent(type.FullName); 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/IBus.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Reflection; 6 | 7 | //DO NOT Change the namespace. 8 | namespace ProjectExtensions.Azure.ServiceBus { 9 | 10 | /// 11 | /// Service Bus interface 12 | /// 13 | public interface IBus { 14 | 15 | /// 16 | /// Called After we prime the bus so that any config needed can be initialized. 17 | /// 18 | void Initialize(); 19 | 20 | /// 21 | /// Get the Number of messages for the topic for a given type 22 | /// 23 | /// The end point message 24 | /// 25 | long MessageCountForType(Type type); 26 | 27 | /// 28 | /// Auto discover all of the Subscribers in the assembly. 29 | /// 30 | /// The assembly to register 31 | void RegisterAssembly(Assembly assembly); 32 | 33 | /// 34 | /// Publish a Message with the given signature. 35 | /// 36 | /// 37 | /// The message to publish. 38 | void Publish(T message); 39 | 40 | /// 41 | /// Publish a Message with the given signature. 42 | /// 43 | /// 44 | /// The message to publish. 45 | /// Metadata to sent with the message. 46 | void Publish(T message, IDictionary metadata = null); 47 | 48 | /// 49 | /// Publish a Message with the given signature. 50 | /// 51 | /// 52 | /// The message to publish. 53 | /// The callback when the message is complete 54 | /// Metadata to sent with the message. 55 | void PublishAsync(T message, Action> resultCallBack, IDictionary metadata = null); 56 | 57 | /// 58 | /// Publish a Message with the given signature. 59 | /// 60 | /// 61 | /// The message to publish. 62 | /// State object that is returned to the user 63 | /// The callback when the message is complete 64 | /// Metadata to sent with the message. 65 | void PublishAsync(T message, object state, Action> resultCallBack, IDictionary metadata = null); 66 | 67 | /// 68 | /// Subscribes to recieve published messages of type T. 69 | /// This method is only necessary if you turned off auto-subscribe. 70 | /// 71 | /// The type of message to subscribe to. 72 | void Subscribe(); 73 | 74 | /// 75 | /// Unsubscribes from receiving published messages of the specified type. 76 | /// 77 | /// The type of message to unsubscribe from. 78 | void Unsubscribe(); 79 | 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/TransientFaultHandling/GlobalSuppressions.cs: -------------------------------------------------------------------------------- 1 | //=============================================================================== 2 | // Microsoft patterns & practices Enterprise Library 3 | // Transient Fault Handling Application Block 4 | //=============================================================================== 5 | // Copyright © Microsoft Corporation. All rights reserved. 6 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY 7 | // OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT 8 | // LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 9 | // FITNESS FOR A PARTICULAR PURPOSE. 10 | //=============================================================================== 11 | 12 | // This file is used by Code Analysis to maintain SuppressMessage 13 | // attributes that are applied to this project. 14 | // Project-level suppressions either have no target or are given 15 | // a specific target and scoped to a namespace, type, member, etc. 16 | // 17 | // To add a suppression to this file, right-click the message in the 18 | // Error List, point to "Suppress Message(s)", and click 19 | // "In Project Suppression File". 20 | // You do not need to add suppressions to this file manually. 21 | 22 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1020:AvoidNamespacesWithFewTypes", Scope = "namespace", Target = "Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling.AzureStorage", Justification = "As designed")] 23 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1020:AvoidNamespacesWithFewTypes", Scope = "namespace", Target = "Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling.Cache", Justification = "As designed")] 24 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1020:AvoidNamespacesWithFewTypes", Scope = "namespace", Target = "Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling.ServiceBus", Justification = "As designed")] 25 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1703:ResourceStringsShouldBeSpelledCorrectly", MessageId = "Backoff", Scope = "resource", Target = "Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling.Configuration.DesignResources.resources", Justification = "As designed")] 26 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Backoff", Scope = "member", Target = "Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling.Configuration.ExponentialBackoffData.#DeltaBackoff", Justification = "As designed")] 27 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Backoff", Scope = "member", Target = "Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling.Configuration.ExponentialBackoffData.#MaxBackoff", Justification = "As designed")] 28 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Backoff", Scope = "member", Target = "Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling.Configuration.ExponentialBackoffData.#MinBackoff", Justification = "As designed")] 29 | [assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Backoff", Scope = "type", Target = "Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling.Configuration.ExponentialBackoffData", Justification = "As designed")] 30 | -------------------------------------------------------------------------------- /src/Tests/ProjectExtensions.Azure.ServiceBus.Tests.Integration/ProjectExtensions.Azure.ServiceBus.Tests.Integration.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {5CA360A8-B3D1-4470-BD73-11F96082E62C} 9 | Library 10 | Properties 11 | ProjectExtensions.Azure.ServiceBus.Tests.Integration 12 | ProjectExtensions.Azure.ServiceBus.Tests.Integration 13 | v4.0 14 | 512 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | pdbonly 27 | true 28 | bin\Release\ 29 | TRACE 30 | prompt 31 | 4 32 | 33 | 34 | 35 | False 36 | ..\..\..\packages\Moq.4.2.1312.1622\lib\net40\Moq.dll 37 | 38 | 39 | False 40 | ..\..\..\packages\NUnit.2.6.3\lib\nunit.framework.dll 41 | 42 | 43 | False 44 | ..\..\..\packages\RhinoMocks.3.6.1\lib\net\Rhino.Mocks.dll 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | Properties\CommonAssemblyInfo.cs 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 71 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus.Autofac/ProjectExtensions.Azure.ServiceBus.Autofac.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {11192756-9ABB-4C2B-8FE5-2DBD4DC0DC36} 9 | Library 10 | Properties 11 | ProjectExtensions.Azure.ServiceBus.Autofac 12 | ProjectExtensions.Azure.ServiceBus.Autofac 13 | v4.0 14 | 512 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | bin\Debug\ProjectExtensions.Azure.ServiceBus.Autofac.XML 25 | 26 | 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | bin\Release\ProjectExtensions.Azure.ServiceBus.Autofac.XML 34 | 35 | 36 | 37 | False 38 | ..\..\packages\Autofac.3.3.0\lib\net40\Autofac.dll 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | Properties\CommonAssemblyInfo.cs 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | {8C8A8531-95AE-41CD-B2AC-6651F104245E} 59 | ProjectExtensions.Azure.ServiceBus 60 | 61 | 62 | 63 | 64 | 65 | 66 | 73 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/Tests/ProjectExtensions.Azure.ServiceBus.Tests.Unit/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus.Ninject/ProjectExtensions.Azure.ServiceBus.Ninject.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {18285A92-F031-45A5-97BB-FE3841DAB434} 9 | Library 10 | Properties 11 | ProjectExtensions.Azure.ServiceBus.Ninject 12 | ProjectExtensions.Azure.ServiceBus.Ninject 13 | v4.0 14 | 512 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | bin\Debug\ProjectExtensions.Azure.ServiceBus.Ninject.XML 25 | 26 | 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | bin\Release\ProjectExtensions.Azure.ServiceBus.Ninject.XML 34 | 35 | 36 | 37 | 38 | 39 | 40 | False 41 | ..\..\packages\Ninject.3.0.1.10\lib\net40\Ninject.dll 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | Properties\CommonAssemblyInfo.cs 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | {8C8A8531-95AE-41CD-B2AC-6651F104245E} 62 | ProjectExtensions.Azure.ServiceBus 63 | 64 | 65 | 66 | 67 | 68 | 69 | 76 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/TransientFaultHandling.Core/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //=============================================================================== 2 | // Microsoft patterns & practices Enterprise Library 3 | // Transient Fault Handling Application Block 4 | //=============================================================================== 5 | // Copyright © Microsoft Corporation. All rights reserved. 6 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY 7 | // OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT 8 | // LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 9 | // FITNESS FOR A PARTICULAR PURPOSE. 10 | //=============================================================================== 11 | 12 | //------------------------------------------------------------------------------ 13 | // 14 | // This code was generated by a tool. 15 | // Runtime Version:4.0.30319.239 16 | // 17 | // Changes to this file may cause incorrect behavior and will be lost if 18 | // the code is regenerated. 19 | // 20 | //------------------------------------------------------------------------------ 21 | 22 | namespace Microsoft.Practices.TransientFaultHandling.Properties { 23 | using System; 24 | 25 | 26 | /// 27 | /// A strongly-typed resource class, for looking up localized strings, etc. 28 | /// 29 | // This class was auto-generated by the StronglyTypedResourceBuilder 30 | // class via a tool like ResGen or Visual Studio. 31 | // To add or remove a member, edit your .ResX file then rerun ResGen 32 | // with the /str option, or rebuild your VS project. 33 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 34 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 35 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 36 | internal class Resources { 37 | 38 | private static global::System.Resources.ResourceManager resourceMan; 39 | 40 | private static global::System.Globalization.CultureInfo resourceCulture; 41 | 42 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 43 | internal Resources() { 44 | } 45 | 46 | /// 47 | /// Returns the cached ResourceManager instance used by this class. 48 | /// 49 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 50 | internal static global::System.Resources.ResourceManager ResourceManager { 51 | get { 52 | if (object.ReferenceEquals(resourceMan, null)) { 53 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.Practices.TransientFaultHandling.Properties.Resources", typeof(Resources).Assembly); 54 | resourceMan = temp; 55 | } 56 | return resourceMan; 57 | } 58 | } 59 | 60 | /// 61 | /// Overrides the current thread's CurrentUICulture property for all 62 | /// resource lookups using this strongly typed resource class. 63 | /// 64 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 65 | internal static global::System.Globalization.CultureInfo Culture { 66 | get { 67 | return resourceCulture; 68 | } 69 | set { 70 | resourceCulture = value; 71 | } 72 | } 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus.StructureMap/ProjectExtensions.Azure.ServiceBus.StructureMap.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {5C526602-9D47-4E02-B3A6-745E9D573994} 9 | Library 10 | Properties 11 | ProjectExtensions.Azure.ServiceBus.StructureMap 12 | ProjectExtensions.Azure.ServiceBus.StructureMap 13 | v4.0 14 | 512 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | bin\Debug\ProjectExtensions.Azure.ServiceBus.StructureMap.XML 25 | 26 | 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | bin\Release\ProjectExtensions.Azure.ServiceBus.StructureMap.XML 34 | 35 | 36 | 37 | ..\..\packages\Unity.2.1.505.0\lib\NET35\Microsoft.Practices.Unity.dll 38 | 39 | 40 | False 41 | ..\..\packages\structuremap.2.6.4.1\lib\net40\StructureMap.dll 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | Properties\CommonAssemblyInfo.cs 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | {8C8A8531-95AE-41CD-B2AC-6651F104245E} 62 | ProjectExtensions.Azure.ServiceBus 63 | 64 | 65 | 66 | 67 | 68 | 69 | 76 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus.Autofac/Container/AutofacAzureBusContainer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using Autofac; 5 | using ProjectExtensions.Azure.ServiceBus.Container; 6 | 7 | namespace ProjectExtensions.Azure.ServiceBus.Autofac.Container { 8 | /// 9 | /// Implementation of for Autofac 10 | /// 11 | public class AutofacAzureBusContainer : AzureBusContainerBase { 12 | IContainer container; 13 | ContainerBuilder builder = new ContainerBuilder(); 14 | List registeredTypes = new List(); 15 | 16 | /// 17 | /// Constructor. 18 | /// 19 | /// Optional autofac container owned by the calling application. 20 | /// If one is not provided, a new one will be created. 21 | public AutofacAzureBusContainer(IContainer container = null) { 22 | this.container = container; 23 | } 24 | 25 | /// 26 | /// Resolve component type of T with optional arguments. 27 | /// 28 | /// 29 | /// 30 | public override T Resolve() { 31 | return container.Resolve(); 32 | } 33 | 34 | /// 35 | /// Resolve component with optional arguments. 36 | /// 37 | /// The type to resolve. 38 | /// 39 | public override object Resolve(Type t) { 40 | return container.Resolve(t); 41 | } 42 | 43 | /// 44 | /// Register an implementation for a service type. 45 | /// 46 | /// The service type. 47 | /// The implementation type. 48 | /// True creates an instance each time resolved. False uses a singleton instance for the entire lifetime of the process. 49 | public override void Register(Type serviceType, Type implementationType, bool perInstance = false) { 50 | var reg = builder.RegisterType(implementationType).As(serviceType); 51 | if (perInstance) { 52 | reg.InstancePerDependency(); 53 | } 54 | else { 55 | reg.SingleInstance(); 56 | } 57 | registeredTypes.Add(serviceType); 58 | } 59 | 60 | /// 61 | /// Registers the configuration instance with the bus if it is not already registered 62 | /// 63 | public override void RegisterConfiguration() { 64 | if (!IsRegistered(typeof(IBusConfiguration))) { 65 | builder.Register(item => BusConfiguration.Instance).As().SingleInstance(); 66 | } 67 | } 68 | 69 | /// 70 | /// Build the container if needed. 71 | /// 72 | public override void Build() { 73 | if (container == null) { 74 | container = builder.Build(); 75 | } 76 | else { 77 | builder.Update(container); 78 | } 79 | builder = new ContainerBuilder(); 80 | registeredTypes.Clear(); 81 | } 82 | 83 | /// 84 | /// Return true if the given type is registered with the container. 85 | /// 86 | /// 87 | /// 88 | public override bool IsRegistered(Type type) { 89 | if (container != null) { 90 | return container.IsRegistered(type) || registeredTypes.Contains(type); 91 | } 92 | else { 93 | return registeredTypes.Contains(type); 94 | } 95 | } 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus.CastleWindsor/ProjectExtensions.Azure.ServiceBus.CastleWindsor.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {69CAB6DE-C753-42F9-9E8F-935B975DBCA2} 9 | Library 10 | Properties 11 | ProjectExtensions.Azure.ServiceBus.CastleWindsor 12 | ProjectExtensions.Azure.ServiceBus.CastleWindsor 13 | v4.0 14 | 512 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | bin\Debug\ProjectExtensions.Azure.ServiceBus.CastleWindsor.XML 25 | 26 | 27 | pdbonly 28 | true 29 | bin\Release\ 30 | TRACE 31 | prompt 32 | 4 33 | bin\Release\ProjectExtensions.Azure.ServiceBus.CastleWindsor.XML 34 | 35 | 36 | 37 | False 38 | ..\..\packages\Castle.Core.3.2.2\lib\net40-client\Castle.Core.dll 39 | 40 | 41 | False 42 | ..\..\packages\Castle.Windsor.3.2.1\lib\net40\Castle.Windsor.dll 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | Properties\CommonAssemblyInfo.cs 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | {8C8A8531-95AE-41CD-B2AC-6651F104245E} 63 | ProjectExtensions.Azure.ServiceBus 64 | 65 | 66 | 67 | 68 | 69 | 70 | 77 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/TransientFaultHandling/Configuration/TransientFaultHandlingDesignTime.cs: -------------------------------------------------------------------------------- 1 | //=============================================================================== 2 | // Microsoft patterns & practices Enterprise Library 3 | // Transient Fault Handling Application Block 4 | //=============================================================================== 5 | // Copyright © Microsoft Corporation. All rights reserved. 6 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY 7 | // OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT 8 | // LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 9 | // FITNESS FOR A PARTICULAR PURPOSE. 10 | //=============================================================================== 11 | 12 | namespace Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling.Configuration 13 | { 14 | internal static class TransientFaultHandlingDesignTime 15 | { 16 | public static class ViewModelTypeNames 17 | { 18 | public const string RetryPolicyConfigurationSettingsViewModel = 19 | "Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling.Configuration.Design.ViewModel.RetryPolicyConfigurationSettingsViewModel, Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling.Configuration"; 20 | 21 | public const string DefaultElementConfigurationProperty = 22 | "Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling.Configuration.Design.ViewModel.DefaultElementConfigurationProperty, Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling.Configuration"; 23 | 24 | public const string TimeSpanElementConfigurationProperty = 25 | "Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling.Configuration.Design.ViewModel.TimeSpanElementConfigurationProperty, Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling.Configuration"; 26 | } 27 | 28 | public static class CommandTypeNames 29 | { 30 | public const string WellKnownRetryStrategyElementCollectionCommand = "Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling.Configuration.Design.ViewModel.Commands.WellKnownRetryStrategyElementCollectionCommand, Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling.Configuration"; 31 | } 32 | 33 | /// 34 | /// Class that contains common editor types used by the designtime. 35 | /// 36 | public static class EditorTypes 37 | { 38 | /// 39 | /// Type name of the TimeSpanEditor class, declared in the Microsoft.Practices.EnterpriseLibrary.WindowsAzure.Autoscaling.Configuration Assembly. 40 | /// 41 | public const string TimeSpanEditor = "Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling.Configuration.ComponentModel.Editors.TimeSpanEditorControl, Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling.Configuration"; 42 | 43 | /// 44 | /// Type name of the FrameworkElement, declared class in the PresentationFramework Assembly. 45 | /// 46 | public const string FrameworkElement = "System.Windows.FrameworkElement, PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"; 47 | } 48 | 49 | public static class ValidatorTypes 50 | { 51 | public const string NameValueCollectionValidator = "Microsoft.Practices.EnterpriseLibrary.Configuration.Design.Validation.NameValueCollectionValidator, Microsoft.Practices.EnterpriseLibrary.Configuration.DesignTime"; 52 | 53 | public const string ExponentialBackoffValidator = "Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling.Configuration.Validation.ExponentialBackoffValidator, Microsoft.Practices.EnterpriseLibrary.WindowsAzure.TransientFaultHandling.Configuration"; 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/BrokeredMessageWrapper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using Microsoft.ServiceBus.Messaging; 6 | 7 | namespace ProjectExtensions.Azure.ServiceBus { 8 | 9 | class BrokeredMessageWrapper : IBrokeredMessage { 10 | 11 | BrokeredMessage message; 12 | 13 | public BrokeredMessageWrapper(BrokeredMessage message) { 14 | this.message = message; 15 | } 16 | 17 | public string ContentType { 18 | get { 19 | return message.ContentType; 20 | } 21 | } 22 | 23 | public string CorrelationId { 24 | get { 25 | return message.CorrelationId; 26 | } 27 | } 28 | 29 | public int DeliveryCount { 30 | get { 31 | return message.DeliveryCount; 32 | } 33 | } 34 | 35 | public DateTime EnqueuedTimeUtc { 36 | get { 37 | return message.EnqueuedTimeUtc; 38 | } 39 | } 40 | 41 | public DateTime ExpiresAtUtc { 42 | get { 43 | return message.ExpiresAtUtc; 44 | } 45 | } 46 | 47 | public string Label { 48 | get { 49 | return message.Label; 50 | } 51 | } 52 | 53 | public DateTime LockedUntilUtc { 54 | get { 55 | return message.LockedUntilUtc; 56 | } 57 | } 58 | 59 | public Guid LockToken { 60 | get { 61 | return message.LockToken; 62 | } 63 | } 64 | 65 | public string MessageId { 66 | get { 67 | return message.MessageId; 68 | } 69 | set { 70 | message.MessageId = value; 71 | } 72 | } 73 | 74 | public IDictionary Properties { 75 | get { 76 | return message.Properties; 77 | } 78 | } 79 | 80 | public string ReplyTo { 81 | get { 82 | return message.ReplyTo; 83 | } 84 | } 85 | 86 | public string ReplyToSessionId { 87 | get { 88 | return message.ReplyToSessionId; 89 | } 90 | } 91 | 92 | public DateTime ScheduledEnqueueTimeUtc { 93 | get { 94 | return message.ScheduledEnqueueTimeUtc; 95 | } 96 | } 97 | 98 | public long SequenceNumber { 99 | get { 100 | return message.SequenceNumber; 101 | } 102 | } 103 | 104 | public string SessionId { 105 | get { 106 | return message.SessionId; 107 | } 108 | } 109 | 110 | public long Size { 111 | get { 112 | return message.Size; 113 | } 114 | } 115 | 116 | public TimeSpan TimeToLive { 117 | get { 118 | return message.TimeToLive; 119 | } 120 | } 121 | 122 | public string To { 123 | get { 124 | return message.To; 125 | } 126 | } 127 | 128 | public void Abandon() { 129 | message.Abandon(); 130 | } 131 | 132 | public void Complete() { 133 | message.Complete(); 134 | } 135 | 136 | public void DeadLetter(string deadLetterReason, string deadLetterErrorDescription) { 137 | message.DeadLetter(deadLetterReason, deadLetterErrorDescription); 138 | } 139 | 140 | public void Dispose() { 141 | message.Dispose(); 142 | } 143 | 144 | public T GetBody() { 145 | return message.GetBody(); 146 | } 147 | 148 | public BrokeredMessage GetMessage() { 149 | return message; 150 | } 151 | 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/TransientFaultHandling.Core/RetryLimitExceededException.cs: -------------------------------------------------------------------------------- 1 | //=============================================================================== 2 | // Microsoft patterns & practices Enterprise Library 3 | // Transient Fault Handling Application Block 4 | //=============================================================================== 5 | // Copyright © Microsoft Corporation. All rights reserved. 6 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY 7 | // OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT 8 | // LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 9 | // FITNESS FOR A PARTICULAR PURPOSE. 10 | //=============================================================================== 11 | 12 | namespace Microsoft.Practices.TransientFaultHandling 13 | { 14 | #region Using references 15 | using System; 16 | using System.Runtime.Serialization; 17 | using TransientFaultHandling.Properties; 18 | #endregion 19 | 20 | /// 21 | /// The special type of exception that provides managed exit from a retry loop. The user code can use this 22 | /// exception to notify the retry policy that no further retry attempts are required. 23 | /// 24 | [Serializable] 25 | public sealed class RetryLimitExceededException : Exception 26 | { 27 | /// 28 | /// Initializes a new instance of the class with a default error message. 29 | /// 30 | public RetryLimitExceededException() 31 | : this(ExceptionMessages.RetryLimitExceeded) 32 | { 33 | } 34 | 35 | /// 36 | /// Initializes a new instance of the class with a specified error message. 37 | /// 38 | /// The message that describes the error. 39 | public RetryLimitExceededException(string message) 40 | : base(message) 41 | { 42 | } 43 | 44 | /// 45 | /// Initializes a new instance of the class with a reference to the inner exception 46 | /// that is the cause of this exception. 47 | /// 48 | /// The exception that is the cause of the current exception. 49 | public RetryLimitExceededException(Exception innerException) 50 | : base(innerException != null ? innerException.Message : ExceptionMessages.RetryLimitExceeded, innerException) 51 | { 52 | } 53 | 54 | /// 55 | /// Initializes a new instance of the class. 56 | /// 57 | /// The message that describes the error. 58 | /// The exception that is the cause of the current exception. 59 | public RetryLimitExceededException(string message, Exception innerException) 60 | : base(message, innerException) 61 | { 62 | } 63 | 64 | /// 65 | /// Initializes a new instance of the class. 66 | /// 67 | /// The that holds the serialized object data about the exception being thrown. 68 | /// The that contains contextual information about the source or destination. 69 | /// The parameter is null. 70 | /// The class name is null or is zero (0). 71 | private RetryLimitExceededException(SerializationInfo info, StreamingContext context) 72 | : base(info, context) 73 | { 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/ProjectExtensions.Azure.ServiceBus/TransientFaultHandling.Core/RetryPolicy.Generic.cs: -------------------------------------------------------------------------------- 1 | //=============================================================================== 2 | // Microsoft patterns & practices Enterprise Library 3 | // Transient Fault Handling Application Block 4 | //=============================================================================== 5 | // Copyright © Microsoft Corporation. All rights reserved. 6 | // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY 7 | // OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT 8 | // LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 9 | // FITNESS FOR A PARTICULAR PURPOSE. 10 | //=============================================================================== 11 | 12 | namespace Microsoft.Practices.TransientFaultHandling 13 | { 14 | using System; 15 | 16 | /// 17 | /// Provides a generic version of the class. 18 | /// 19 | /// The type implementing the interface that is responsible for detecting transient conditions. 20 | public class RetryPolicy : RetryPolicy where T : ITransientErrorDetectionStrategy, new() 21 | { 22 | /// 23 | /// Initializes a new instance of the RetryPolicy class with the specified number of retry attempts and parameters defining the progressive delay between retries. 24 | /// 25 | /// The retry strategy to use for this retry policy. 26 | public RetryPolicy(RetryStrategy retryStrategy) 27 | : base(new T(), retryStrategy) 28 | { 29 | } 30 | 31 | /// 32 | /// Initializes a new instance of the RetryPolicy class with the specified number of retry attempts and default fixed time interval between retries. 33 | /// 34 | /// The number of retry attempts. 35 | public RetryPolicy(int retryCount) 36 | : base(new T(), retryCount) 37 | { 38 | } 39 | 40 | /// 41 | /// Initializes a new instance of the RetryPolicy class with the specified number of retry attempts and fixed time interval between retries. 42 | /// 43 | /// The number of retry attempts. 44 | /// The interval between retries. 45 | public RetryPolicy(int retryCount, TimeSpan retryInterval) 46 | : base(new T(), retryCount, retryInterval) 47 | { 48 | } 49 | 50 | /// 51 | /// Initializes a new instance of the RetryPolicy class with the specified number of retry attempts and back-off parameters for calculating the exponential delay between retries. 52 | /// 53 | /// The number of retry attempts. 54 | /// The minimum back-off time. 55 | /// The maximum back-off time. 56 | /// The time value that will be used for calculating a random delta in the exponential delay between retries. 57 | public RetryPolicy(int retryCount, TimeSpan minBackoff, TimeSpan maxBackoff, TimeSpan deltaBackoff) 58 | : base(new T(), retryCount, minBackoff, maxBackoff, deltaBackoff) 59 | { 60 | } 61 | 62 | /// 63 | /// Initializes a new instance of the RetryPolicy class with the specified number of retry attempts and parameters defining the progressive delay between retries. 64 | /// 65 | /// The number of retry attempts. 66 | /// The initial interval that will apply for the first retry. 67 | /// The incremental time value that will be used for calculating the progressive delay between retries. 68 | public RetryPolicy(int retryCount, TimeSpan initialInterval, TimeSpan increment) 69 | : base(new T(), retryCount, initialInterval, increment) 70 | { 71 | } 72 | } 73 | } 74 | --------------------------------------------------------------------------------