forked from hibernating-rhinos/rhino-esb
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'simpler-headers-interface'
- Loading branch information
Showing
8 changed files
with
116 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 0 additions & 70 deletions
70
Rhino.ServiceBus.Tests/RhinoQueues/CanAddHeadersToMessage.cs
This file was deleted.
Oops, something went wrong.
90 changes: 90 additions & 0 deletions
90
Rhino.ServiceBus.Tests/RhinoQueues/CustomizingMessageConstruction.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using System; | ||
using System.Collections.Specialized; | ||
using Castle.Core; | ||
using Castle.MicroKernel.Registration; | ||
using Castle.Windsor; | ||
using Rhino.Queues; | ||
using Rhino.ServiceBus.Impl; | ||
using Rhino.ServiceBus.Internal; | ||
using Rhino.ServiceBus.RhinoQueues; | ||
using Xunit; | ||
|
||
namespace Rhino.ServiceBus.Tests.RhinoQueues | ||
{ | ||
public class CustomizingMessageConstruction | ||
{ | ||
|
||
[Fact] | ||
public void it_should_add_custom_header_to_headers_collection_using_builder() | ||
{ | ||
using( var container = new WindsorContainer("RhinoQueues/RhinoQueues.config")) | ||
{ | ||
container.Register(Component.For<IMessageBuilder<MessagePayload>>().ImplementedBy<CustomHeaderBuilder>());//before facility | ||
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_using_interface() | ||
{ | ||
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"]); | ||
} | ||
|
||
} | ||
|
||
public class CustomHeaderBuilder : IMessageBuilder<MessagePayload> | ||
{ | ||
private IMessageBuilder<MessagePayload> inner; | ||
|
||
public CustomHeaderBuilder(IMessageBuilder<MessagePayload> inner) | ||
{ | ||
this.inner = inner; | ||
} | ||
|
||
public MessagePayload BuildFromMessageBatch(params object[] msgs) | ||
{ | ||
var payload = inner.BuildFromMessageBatch(msgs); | ||
Contextualize(payload); | ||
return payload; | ||
} | ||
|
||
public void Initialize(Endpoint source) | ||
{ | ||
inner.Initialize(source); | ||
} | ||
|
||
private static void Contextualize(MessagePayload message) | ||
{ | ||
message.Headers.Add("user-id","mikey"); | ||
} | ||
} | ||
public class AppIdentityCustomizer : ICustomizeMessageHeaders | ||
{ | ||
public void Customize(NameValueCollection headers) | ||
{ | ||
headers.Add("user-id","mikey"); | ||
} | ||
} | ||
|
||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System.Collections.Specialized; | ||
|
||
namespace Rhino.ServiceBus | ||
{ | ||
public interface ICustomizeMessageHeaders | ||
{ | ||
void Customize(NameValueCollection headers); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
Rhino.ServiceBus/IMessageBuilder.cs → Rhino.ServiceBus/Internal/IMessageBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
namespace Rhino.ServiceBus | ||
namespace Rhino.ServiceBus.Internal | ||
{ | ||
public interface IMessageBuilder<T> | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters