Skip to content

Commit

Permalink
Merge from rhino-esb/rhino-esb
Browse files Browse the repository at this point in the history
  • Loading branch information
Philip Hoy authored and Philip Hoy committed Jul 1, 2010
1 parent 1430fd5 commit c82b050
Show file tree
Hide file tree
Showing 27 changed files with 1,540 additions and 388 deletions.
4 changes: 3 additions & 1 deletion Rhino.ServiceBus.Host/Rhino.ServiceBus.Host.csproj
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand All @@ -12,6 +12,8 @@
<AssemblyName>Rhino.ServiceBus.Host</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\ayende-open-source.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down
98 changes: 98 additions & 0 deletions Rhino.ServiceBus.Tests/CanSendMsgsFromOneWayBusUsingRhinoQueues.cs
@@ -0,0 +1,98 @@
using System;
using System.IO;
using System.Threading;
using System.Transactions;
using Castle.Windsor;
using Castle.Windsor.Configuration.Interpreters;
using Rhino.ServiceBus.Impl;
using Rhino.ServiceBus.Internal;
using Rhino.ServiceBus.RhinoQueues;
using Rhino.ServiceBus.Tests.RhinoQueues;
using Xunit;

namespace Rhino.ServiceBus.Tests
{
public class CanSendMsgsFromOneWayBusUsingRhinoQueues : WithDebugging,IDisposable
{
private WindsorContainer container;

public CanSendMsgsFromOneWayBusUsingRhinoQueues()
{
if (Directory.Exists("one_way.esent"))
Directory.Delete("one_way.esent", true);
if (Directory.Exists("test_queue.esent"))
Directory.Delete("test_queue.esent", true);
if (Directory.Exists("test_queue_subscriptions.esent"))
Directory.Delete("test_queue_subscriptions.esent", true);
container = new WindsorContainer(new XmlInterpreter("OneWayBusRhinoQueues.config"));
container.Kernel.AddFacility("rhino.esb", new RhinoServiceBusFacility());
container.AddComponent<StringConsumer>();
StringConsumer.Value = null;
StringConsumer.Event = new ManualResetEvent(false);
}



[Fact]
public void SendMessageToRemoteBus()
{
using (var bus = container.Resolve<IStartableServiceBus>())
{
bus.Start();
var transport = new RhinoQueuesTransport(new Uri("null://nowhere:24689/middle"),
new EndpointRouter(), container.Resolve<IMessageSerializer>(),
1, "one_way.esent", IsolationLevel.ReadCommitted, 5);
var oneWay = new RhinoQueuesOneWayBus(new[]
{
new MessageOwner
{
Endpoint = bus.Endpoint.Uri,
Name = "System",
},
}, transport);

oneWay.Send("hello there, one way");

StringConsumer.Event.WaitOne();

Assert.Equal("hello there, one way", StringConsumer.Value);
}
}

[Fact]
public void SendMessageToRemoteBusFromConfigDrivenOneWayBus()
{
using (var bus = container.Resolve<IStartableServiceBus>())
{
bus.Start();

using (var c = new WindsorContainer(new XmlInterpreter("OneWayBusRhinoQueues.config")))
{
c.Kernel.AddFacility("one.way.rhino.esb", new OnewayRhinoServiceBusFacility());
c.Resolve<IOnewayBus>().Send("hello there, one way");
StringConsumer.Event.WaitOne();
Assert.Equal("hello there, one way", StringConsumer.Value);
}


}
}

public class StringConsumer : ConsumerOf<string>
{
public static ManualResetEvent Event;
public static string Value;

public void Consume(string pong)
{
Value = pong;
Event.Set();
}
}

public void Dispose()
{
container.Dispose();
}
}
}
21 changes: 21 additions & 0 deletions Rhino.ServiceBus.Tests/OneWayBusRhinoQueues.config
@@ -0,0 +1,21 @@
<castle>
<facilities>
<facility id="rhino.esb" >
<bus name="test_queue"
threadCount="1"
numberOfRetries="5"
endpoint="rhino.queues://localhost/test_queue"
queueIsolationLevel="ReadCommitted" />
<messages>
<add name="Rhino.ServiceBus.Tests"
endpoint="rhino.queues://localhost/test_queue"/>
</messages>
</facility>
<facility id="one.way.rhino.esb" >
<messages>
<add name="System.String"
endpoint="rhino.queues://localhost/test_queue"/>
</messages>
</facility>
</facilities>
</castle>
16 changes: 9 additions & 7 deletions Rhino.ServiceBus.Tests/Rhino.ServiceBus.Tests.csproj
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand All @@ -12,6 +12,8 @@
<AssemblyName>Rhino.ServiceBus.Tests</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\ayende-open-source.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -31,15 +33,11 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Castle.Core, Version=1.1.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<Reference Include="Castle.Core, Version=1.2.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\SharedLibs\Castle.Core.dll</HintPath>
</Reference>
<Reference Include="Castle.MicroKernel, Version=2.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\SharedLibs\Castle.MicroKernel.dll</HintPath>
</Reference>
<Reference Include="Castle.Windsor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<Reference Include="Castle.Windsor, Version=2.1.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\SharedLibs\Castle.Windsor.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -110,6 +108,7 @@
<Compile Include="BusSubscriptionTests.cs" />
<Compile Include="CanRouteMessageToConsumerThroughContainer.cs" />
<Compile Include="CanSendMsgsFromOneWayBus.cs" />
<Compile Include="CanSendMsgsFromOneWayBusUsingRhinoQueues.cs" />
<Compile Include="DelayedMessages.cs" />
<Compile Include="DataStructures\LRUSetTest.cs" />
<Compile Include="DataStructures\HashtableTest.cs" />
Expand Down Expand Up @@ -176,6 +175,9 @@
<None Include="BusOnTransactionalQueue.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="OneWayBusRhinoQueues.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="LoadBalancer\BusWithAcceptingWorkLoadBalancer.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
8 changes: 4 additions & 4 deletions Rhino.ServiceBus.sln
@@ -1,12 +1,12 @@

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Starbucks", "Starbucks", "{64DC50EF-F634-4E75-8375-ACC6D42E2DB4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rhino.ServiceBus", "Rhino.ServiceBus\Rhino.ServiceBus.csproj", "{1B21C8A5-5E0E-412B-A7F4-9F28B4427F21}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rhino.ServiceBus.Tests", "Rhino.ServiceBus.Tests\Rhino.ServiceBus.Tests.csproj", "{EAC59871-8B6B-4A1B-A2AE-69F7194F047E}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Starbucks", "Starbucks", "{64DC50EF-F634-4E75-8375-ACC6D42E2DB4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Starbucks", "Samples\Starbucks\Starbucks.csproj", "{0FC43226-8030-46FC-A2AB-D064207FF364}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Rhino.ServiceBus.Host", "Rhino.ServiceBus.Host\Rhino.ServiceBus.Host.csproj", "{8FBBDD2A-A832-4827-9325-C670B6DC06FB}"
Expand Down
2 changes: 2 additions & 0 deletions Rhino.ServiceBus/IOnewayBus.cs
@@ -1,3 +1,5 @@
using System;

namespace Rhino.ServiceBus
{
public interface IOnewayBus
Expand Down
1 change: 1 addition & 0 deletions Rhino.ServiceBus/Impl/DefaultServiceBus.cs
Expand Up @@ -3,6 +3,7 @@
using System.Diagnostics;
using System.Linq;
using Castle.MicroKernel;
using Castle.MicroKernel.Context;
using Castle.MicroKernel.Proxy;
using log4net;
using Rhino.ServiceBus.Exceptions;
Expand Down
6 changes: 5 additions & 1 deletion Rhino.ServiceBus/Impl/MessageOwnersConfigReader.cs
Expand Up @@ -15,7 +15,7 @@ public MessageOwnersConfigReader(IConfiguration configuration, ICollection<Messa
this.configuration = configuration;
this.messageOwners = messageOwners;
}

public string EndpointScheme { get; private set; }
public void ReadMessageOwners()
{
IConfiguration messageConfig = configuration.Children["messages"];
Expand All @@ -36,6 +36,10 @@ public void ReadMessageOwners()
try
{
ownerEndpoint = new Uri(uriString);
if(EndpointScheme==null)
{
EndpointScheme = ownerEndpoint.Scheme;
}
}
catch (Exception e)
{
Expand Down
62 changes: 48 additions & 14 deletions Rhino.ServiceBus/Impl/OnewayRhinoServiceBusFacility.cs
@@ -1,10 +1,13 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Transactions;
using Castle.Core;
using Castle.MicroKernel.Facilities;
using Castle.MicroKernel.Registration;
using Rhino.ServiceBus.Internal;
using Rhino.ServiceBus.Msmq;
using Rhino.ServiceBus.RhinoQueues;
using Rhino.ServiceBus.Serializers;
using System.Linq;

Expand All @@ -22,27 +25,58 @@ public void UseMessageSerializer<TMessageSerializer>()

protected override void Init()
{
new MessageOwnersConfigReader(FacilityConfig, messageOwners).ReadMessageOwners();

var messageOwnersReader = new MessageOwnersConfigReader(FacilityConfig, messageOwners);
messageOwnersReader.ReadMessageOwners();
if (IsRhinoQueues(messageOwnersReader.EndpointScheme))
{
var path = Path.GetFullPath(AppDomain.CurrentDomain.BaseDirectory);
Kernel.Register(
Component.For<ITransport>()
.LifeStyle.Is(LifestyleType.Singleton)
.ImplementedBy(typeof (RhinoQueuesTransport))
.DependsOn(new
{
threadCount = 1,
endpoint = new Uri("null://nowhere:24689/middle"),
queueIsolationLevel = IsolationLevel.ReadCommitted,
numberOfRetries = 5,
path = Path.Combine(path,"one_way.esent")
}),
Component.For<IOnewayBus>()
.LifeStyle.Is(LifestyleType.Singleton)
.ImplementedBy<RhinoQueuesOneWayBus>()
.DependsOn(new {messageOwners = messageOwners.ToArray()})
);

}
else
{
Kernel.Register(
Component.For<IMessageBuilder>()
.LifeStyle.Is(LifestyleType.Singleton)
.ImplementedBy<MessageBuilder>(),
Component.For<IOnewayBus>()
.LifeStyle.Is(LifestyleType.Singleton)
.ImplementedBy<OnewayBus>()
.DependsOn(new {messageOwners = messageOwners.ToArray()}));

}
Kernel.Register(
Component.For<IMessageBuilder>()
.LifeStyle.Is(LifestyleType.Singleton)
.ImplementedBy<MessageBuilder>(),
Component.For<IOnewayBus>()
.LifeStyle.Is(LifestyleType.Singleton)
.ImplementedBy<OnewayBus>()
.DependsOn(new{messageOwners = messageOwners.ToArray()}),
Component.For<IReflection>()
.LifeStyle.Is(LifestyleType.Singleton)
.ImplementedBy<DefaultReflection>(),

.LifeStyle.Is(LifestyleType.Singleton)
.ImplementedBy<DefaultReflection>(),
Component.For<IMessageSerializer>()
.LifeStyle.Is(LifestyleType.Singleton)
.ImplementedBy(serializerImpl),
Component.For<IEndpointRouter>()
.ImplementedBy<EndpointRouter>()
);
.ImplementedBy<EndpointRouter>()
);

}

private static bool IsRhinoQueues(string endpointScheme)
{
return endpointScheme.Equals("rhino.queues", StringComparison.InvariantCultureIgnoreCase);
}
}
}
13 changes: 6 additions & 7 deletions Rhino.ServiceBus/Rhino.ServiceBus.csproj
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand All @@ -12,6 +12,8 @@
<AssemblyName>Rhino.ServiceBus</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\ayende-open-source.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand All @@ -33,15 +35,11 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Castle.Core, Version=1.1.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<Reference Include="Castle.Core, Version=1.2.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\SharedLibs\Castle.Core.dll</HintPath>
</Reference>
<Reference Include="Castle.MicroKernel, Version=2.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\SharedLibs\Castle.MicroKernel.dll</HintPath>
</Reference>
<Reference Include="Castle.Windsor, Version=2.0.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<Reference Include="Castle.Windsor, Version=2.1.0.0, Culture=neutral, PublicKeyToken=407dd0808d44fbdc, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\SharedLibs\Castle.Windsor.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -120,6 +118,7 @@
<Compile Include="Messages\ReadyToWork.cs" />
<Compile Include="Msmq\AbstractMsmqListener.cs" />
<Compile Include="Msmq\QueueCreationModule.cs" />
<Compile Include="RhinoQueues\RhinoQueuesOneWayBus.cs" />
<Compile Include="Transport\SubQueue.cs" />
<Compile Include="Msmq\TransportActions\ShutDownAction.cs" />
<Compile Include="Msmq\TransportState.cs" />
Expand Down
23 changes: 23 additions & 0 deletions Rhino.ServiceBus/RhinoQueues/RhinoQueuesOneWayBus.cs
@@ -0,0 +1,23 @@
using Rhino.ServiceBus.Impl;
using Rhino.ServiceBus.Internal;

namespace Rhino.ServiceBus.RhinoQueues
{
public class RhinoQueuesOneWayBus : IOnewayBus
{
private MessageOwnersSelector messageOwners;
private ITransport transport;

public RhinoQueuesOneWayBus(MessageOwner[] messageOwners, ITransport transport)
{
this.messageOwners = new MessageOwnersSelector(messageOwners, new EndpointRouter());
this.transport = transport;
this.transport.Start();
}

public void Send(params object[] msgs)
{
transport.Send(messageOwners.GetEndpointForMessageBatch(msgs), msgs);
}
}
}

0 comments on commit c82b050

Please sign in to comment.