Permalink
Browse files

added support for subscription discovery when first messge in batch d…

…oes not have a subscription
  • Loading branch information...
1 parent ee2fff2 commit eef109f2e42934a09ba59f53016c884045faaeec mnichols committed Aug 2, 2010
Showing with 34 additions and 2 deletions.
  1. +26 −0 Rhino.ServiceBus.Tests/TwoBusesCommunicating.cs
  2. +8 −2 Rhino.ServiceBus/Impl/DefaultServiceBus.cs
@@ -51,6 +51,32 @@ public void Can_send_messages_from_one_end_to_the_other()
Assert.True(PongHandler.GotReply);
}
}
+ [Fact]
+ public void Can_notify_when_at_least_one_message_has_handler()
+ {
+ using(var bus1 = container1.Resolve<IStartableServiceBus>())
+ using(var bus2 = container2.Resolve<IStartableServiceBus>())
+ {
+ var subscriptionStorage2 = container2.Resolve<ISubscriptionStorage>();
+
+ var wait = new ManualResetEvent(false);
+ subscriptionStorage2.SubscriptionChanged += () => wait.Set();
+
+ bus1.Start();
+ bus2.Start();
+
+ PongHandler.ResetEvent = new ManualResetEvent(false);
+ PongHandler.GotReply = false;
+
+ wait.WaitOne(TimeSpan.FromSeconds(30), false);
+
+ bus2.Notify("ping", new Ping());
+
+ PongHandler.ResetEvent.WaitOne(TimeSpan.FromSeconds(30), false);
+
+ Assert.True(PongHandler.GotReply);
+ }
+ }
public class Ping
{
@@ -350,8 +350,14 @@ private bool PublishInternal(object[] messages)
bool sentMsg = false;
if (messages.Length == 0)
throw new MessagePublicationException("Cannot publish an empty message batch");
- object msg = messages[0];
- IEnumerable<Uri> subscriptions = subscriptionStorage.GetSubscriptionsFor(msg.GetType());
+
+ var subscriptions = new Uri[0];
+ var index = -1;
+ while(subscriptions.Length==0 && index<messages.Length)
+ {
+ subscriptions = subscriptionStorage.GetSubscriptionsFor(messages[++index].GetType()).ToArray();
+ }
+
foreach (Uri subscription in subscriptions)
{
transport.Send(endpointRouter.GetRoutedEndpoint(subscription), messages);

0 comments on commit eef109f

Please sign in to comment.