Skip to content

Commit

Permalink
Fixed a bug in handling callbacks via main queue.
Browse files Browse the repository at this point in the history
  • Loading branch information
SzymonPobiega committed Sep 29, 2014
1 parent 781c1eb commit f987ce4
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
</None>
</ItemGroup>
<ItemGroup>
<Compile Include="When_callback_receiver_is_disabled.cs" />
<Compile Include="App_Packages\NSB.AcceptanceTests.5.0.0\Audit\When_a_message_is_audited.cs" />
<Compile Include="App_Packages\NSB.AcceptanceTests.5.0.0\Audit\When_using_auditing_as_a_feature.cs" />
<Compile Include="App_Packages\NSB.AcceptanceTests.5.0.0\Audit\When_using_audit_message_is_received.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
namespace NServiceBus.SqlServer.AcceptanceTests
{
using NServiceBus.AcceptanceTesting;
using NServiceBus.AcceptanceTests.EndpointTemplates;
using NUnit.Framework;

public class When_callback_receiver_is_disabled
{
[Test]
public void Should_still_receive_callbacks()
{
var context = new Context();

Scenario.Define(context)
.WithEndpoint<ServerThatRespondsToCallbacks>()
.WithEndpoint<ScaledOutClient>(b => b.Given((bus, c) => bus.Send(new MyRequest())
.Register(m =>
{
c.GotTheCallback = true;
})))
.Done(c => context.GotTheCallback)
.Run();

Assert.True(context.GotTheCallback, "Should get the callback");
}

public class ScaledOutClient : EndpointConfigurationBuilder
{
public ScaledOutClient()
{
EndpointSetup<DefaultServer>(c => c.UseTransport<SqlServerTransport>().DisableCallbackReceiver())
.AddMapping<MyRequest>(typeof(ServerThatRespondsToCallbacks));
}
}

public class ServerThatRespondsToCallbacks : EndpointConfigurationBuilder
{
public ServerThatRespondsToCallbacks()
{
EndpointSetup<DefaultServer>();
}

class MyEventHandler : IHandleMessages<MyRequest>
{
public IBus Bus { get; set; }

public void Handle(MyRequest message)
{
Bus.Return(1);
}
}
}

class MyRequest : IMessage
{
}

class Context : ScenarioContext
{
public bool GotTheCallback { get; set; }
}
}
}
6 changes: 4 additions & 2 deletions src/NServiceBus.SqlServer/SqlServerMessageSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ public void Send(TransportMessage message, SendOptions sendOptions)
}

//set our callback address
message.Headers[CallbackHeaderKey] = CallbackQueue;

if (!string.IsNullOrEmpty(CallbackQueue))
{
message.Headers[CallbackHeaderKey] = CallbackQueue;
}
var queue = address.Queue;
try
{
Expand Down
8 changes: 5 additions & 3 deletions src/NServiceBus.SqlServer/SqlServerTransportFeature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ protected override void Configure(FeatureConfigurationContext context, string co
container.ConfigureComponent<SqlServerQueueCreator>(DependencyLifecycle.InstancePerCall)
.ConfigureProperty(p => p.ConnectionString, connectionString);

container.ConfigureComponent<SqlServerMessageSender>(DependencyLifecycle.InstancePerCall)
var senderConfig = container.ConfigureComponent<SqlServerMessageSender>(DependencyLifecycle.InstancePerCall)
.ConfigureProperty(p => p.DefaultConnectionString, connectionString)
.ConfigureProperty(p => p.ConnectionStringCollection, collection)
.ConfigureProperty(p => p.CallbackQueue, callbackQueue);
.ConfigureProperty(p => p.ConnectionStringCollection, collection);


container.ConfigureComponent<SqlServerPollingDequeueStrategy>(DependencyLifecycle.InstancePerCall)
.ConfigureProperty(p => p.ConnectionString, connectionString);
Expand All @@ -74,6 +74,8 @@ protected override void Configure(FeatureConfigurationContext context, string co

if (useCallbackReceiver)
{
senderConfig.ConfigureProperty(p => p.CallbackQueue, callbackQueue);

var callbackAddress = Address.Parse(callbackQueue);

context.Container.ConfigureComponent<CallbackQueueCreator>(DependencyLifecycle.InstancePerCall)
Expand Down

0 comments on commit f987ce4

Please sign in to comment.