Permalink
Browse files

added icustomizeheaders interface

  • Loading branch information...
1 parent a3a06cb commit fe252b4d845bca1292fe6c0a9517227740ac75bd mnichols committed Jul 5, 2010
View
57 Rhino.ServiceBus.Tests/RhinoQueues/CustomizingMessageConstruction.cs
@@ -1,4 +1,6 @@
using System;
+using System.Collections.Specialized;
+using Castle.Core;
using Castle.MicroKernel.Registration;
using Castle.Windsor;
using Rhino.Queues;
@@ -8,30 +10,42 @@
namespace Rhino.ServiceBus.Tests.RhinoQueues
{
- public class CustomizingMessageConstruction:IDisposable
+ public class CustomizingMessageConstruction
{
- private WindsorContainer container;
-
- public CustomizingMessageConstruction()
+
+ [Fact]
+ public void it_should_add_custom_header_to_headers_collection_using_builder()
{
- container = new WindsorContainer("RhinoQueues/RhinoQueues.config");
+ using( var container = new WindsorContainer("RhinoQueues/RhinoQueues.config"))
+ {
+ container.Register(Component.For<IMessageBuilder<MessagePayload>>().ImplementedBy<CustomHeaderBuilder>());//before facility
+ container.AddFacility("rhino.esb", new RhinoServiceBusFacility());
- container.Register(Component.For<IMessageBuilder<MessagePayload>>().ImplementedBy<CustomHeaderBuilder>());
- container.AddFacility("rhino.esb", new RhinoServiceBusFacility());
-
+ var builder = container.Resolve<IMessageBuilder<MessagePayload>>();
+ builder.Initialize(new Endpoint { Uri = RhinoQueuesOneWayBus.NullEndpoint });
+ var msg = builder.BuildFromMessageBatch("somemsg");
+ Assert.NotNull(msg);
+ Assert.NotEqual(0, msg.Data.Length);
+ Assert.Equal("mikey", msg.Headers["user-id"]);
+ }
}
-
[Fact]
- public void it_should_add_custom_header_to_headers_collection()
+ public void it_should_add_custom_header_to_headers_collection_using_interface()
{
- var builder = container.Resolve<IMessageBuilder<MessagePayload>>();
- builder.Initialize(new Endpoint {Uri = RhinoQueuesOneWayBus.NullEndpoint});
- var msg = builder.BuildFromMessageBatch("somemsg");
- Assert.NotNull(msg);
- Assert.NotEqual(0,msg.Data.Length);
- Assert.Equal("mikey",msg.Headers["user-id"]);
+ using (var container = new WindsorContainer("RhinoQueues/RhinoQueues.config"))
+ {
+ container.AddFacility("rhino.esb", new RhinoServiceBusFacility());
+ container.Register(Component.For<ICustomizeMessageHeaders>().ImplementedBy<AppIdentityCustomizer>().LifeStyle.Is(LifestyleType.Transient));
+
+ var builder = container.Resolve<IMessageBuilder<MessagePayload>>();
+ builder.Initialize(new Endpoint { Uri = RhinoQueuesOneWayBus.NullEndpoint });
+ var msg = builder.BuildFromMessageBatch("somemsg");
+ Assert.NotNull(msg);
+ Assert.NotEqual(0, msg.Data.Length);
+ Assert.Equal("mikey", msg.Headers["user-id"]);
+ }
}
@@ -61,10 +75,15 @@ private static void Contextualize(MessagePayload message)
message.Headers.Add("user-id","mikey");
}
}
-
- public void Dispose()
+ public class AppIdentityCustomizer : ICustomizeMessageHeaders
{
- container.Dispose();
+ public void Customize(NameValueCollection headers)
+ {
+ headers.Add("user-id","mikey");
+ }
}
+
}
+
+
}
View
9 Rhino.ServiceBus/ICustomizeMessageHeaders.cs
@@ -0,0 +1,9 @@
+using System.Collections.Specialized;
+
+namespace Rhino.ServiceBus
+{
+ public interface ICustomizeMessageHeaders
+ {
+ void Customize(NameValueCollection headers);
+ }
+}
View
0 Rhino.ServiceBus/IMessageBuilder.cs → Rhino.ServiceBus/Internal/IMessageBuilder.cs
File renamed without changes.
View
3 Rhino.ServiceBus/Rhino.ServiceBus.csproj
@@ -97,6 +97,7 @@
<Compile Include="Hosting\DefaultHost.cs" />
<Compile Include="Hosting\RemoteAppDomainHost.cs" />
<Compile Include="Hosting\RemoteAppDomainLoadBalancerHost.cs" />
+ <Compile Include="ICustomizeMessageHeaders.cs" />
<Compile Include="Impl\EndpointRouter.cs" />
<Compile Include="Endpoint.cs" />
<Compile Include="Internal\IEndpointRouter.cs" />
@@ -217,7 +218,7 @@
<Compile Include="Messages\QueryReadyForWorkQueueUri.cs" />
<Compile Include="Messages\Reroute.cs" />
<Compile Include="Msmq\EndpointExtensions.cs" />
- <Compile Include="IMessageBuilder.cs" />
+ <Compile Include="Internal\IMessageBuilder.cs" />
<Compile Include="Msmq\MsmqMessageBuilder.cs" />
<Compile Include="Transport\MessageHandlingCompletion.cs" />
<Compile Include="Msmq\OpenedQueue.cs" />
View
13 Rhino.ServiceBus/RhinoQueues/RhinoQueuesMessageBuilder.cs
@@ -1,4 +1,5 @@
using System;
+using System.Collections.Specialized;
using System.IO;
using Rhino.Queues;
using Rhino.ServiceBus.Internal;
@@ -40,9 +41,19 @@ public MessagePayload BuildFromMessageBatch(params object[] msgs)
{"source", endpoint.Uri.ToString()},
}
};
+
+ TryCustomizeHeaders(payload.Headers);
return payload;
}
-
+
+ private void TryCustomizeHeaders(NameValueCollection headers)
+ {
+ if (MessageHeaders == null)
+ return;
+ MessageHeaders.Customize(headers);
+ }
+
+ public ICustomizeMessageHeaders MessageHeaders { get; set; }
public void Initialize(Endpoint source)
{
endpoint = source;

0 comments on commit fe252b4

Please sign in to comment.