Skip to content

Commit

Permalink
added support for subscription discovery when first messge in batch d…
Browse files Browse the repository at this point in the history
…oes not have a subscription
  • Loading branch information
mnichols committed Aug 2, 2010
1 parent ee2fff2 commit eef109f
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
26 changes: 26 additions & 0 deletions Rhino.ServiceBus.Tests/TwoBusesCommunicating.cs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -51,6 +51,32 @@ public void Can_send_messages_from_one_end_to_the_other()
Assert.True(PongHandler.GotReply); 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 public class Ping
{ {
Expand Down
10 changes: 8 additions & 2 deletions Rhino.ServiceBus/Impl/DefaultServiceBus.cs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -350,8 +350,14 @@ private bool PublishInternal(object[] messages)
bool sentMsg = false; bool sentMsg = false;
if (messages.Length == 0) if (messages.Length == 0)
throw new MessagePublicationException("Cannot publish an empty message batch"); 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) foreach (Uri subscription in subscriptions)
{ {
transport.Send(endpointRouter.GetRoutedEndpoint(subscription), messages); transport.Send(endpointRouter.GetRoutedEndpoint(subscription), messages);
Expand Down

0 comments on commit eef109f

Please sign in to comment.