diff --git a/src/NServiceBus.SqlServer.AcceptanceTests/NServiceBus.SqlServer.AcceptanceTests.csproj b/src/NServiceBus.SqlServer.AcceptanceTests/NServiceBus.SqlServer.AcceptanceTests.csproj index 1531e0b5f..d219b7faa 100644 --- a/src/NServiceBus.SqlServer.AcceptanceTests/NServiceBus.SqlServer.AcceptanceTests.csproj +++ b/src/NServiceBus.SqlServer.AcceptanceTests/NServiceBus.SqlServer.AcceptanceTests.csproj @@ -63,6 +63,7 @@ + diff --git a/src/NServiceBus.SqlServer.AcceptanceTests/When_callback_receiver_is_disabled.cs b/src/NServiceBus.SqlServer.AcceptanceTests/When_callback_receiver_is_disabled.cs new file mode 100644 index 000000000..93ee034a7 --- /dev/null +++ b/src/NServiceBus.SqlServer.AcceptanceTests/When_callback_receiver_is_disabled.cs @@ -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() + .WithEndpoint(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(c => c.UseTransport().DisableCallbackReceiver()) + .AddMapping(typeof(ServerThatRespondsToCallbacks)); + } + } + + public class ServerThatRespondsToCallbacks : EndpointConfigurationBuilder + { + public ServerThatRespondsToCallbacks() + { + EndpointSetup(); + } + + class MyEventHandler : IHandleMessages + { + public IBus Bus { get; set; } + + public void Handle(MyRequest message) + { + Bus.Return(1); + } + } + } + + class MyRequest : IMessage + { + } + + class Context : ScenarioContext + { + public bool GotTheCallback { get; set; } + } + } +} \ No newline at end of file diff --git a/src/NServiceBus.SqlServer/SqlServerMessageSender.cs b/src/NServiceBus.SqlServer/SqlServerMessageSender.cs index 99b212166..87e725a0f 100644 --- a/src/NServiceBus.SqlServer/SqlServerMessageSender.cs +++ b/src/NServiceBus.SqlServer/SqlServerMessageSender.cs @@ -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 { diff --git a/src/NServiceBus.SqlServer/SqlServerTransportFeature.cs b/src/NServiceBus.SqlServer/SqlServerTransportFeature.cs index 5877be96b..b3dc33d27 100644 --- a/src/NServiceBus.SqlServer/SqlServerTransportFeature.cs +++ b/src/NServiceBus.SqlServer/SqlServerTransportFeature.cs @@ -62,10 +62,10 @@ protected override void Configure(FeatureConfigurationContext context, string co container.ConfigureComponent(DependencyLifecycle.InstancePerCall) .ConfigureProperty(p => p.ConnectionString, connectionString); - container.ConfigureComponent(DependencyLifecycle.InstancePerCall) + var senderConfig = container.ConfigureComponent(DependencyLifecycle.InstancePerCall) .ConfigureProperty(p => p.DefaultConnectionString, connectionString) - .ConfigureProperty(p => p.ConnectionStringCollection, collection) - .ConfigureProperty(p => p.CallbackQueue, callbackQueue); + .ConfigureProperty(p => p.ConnectionStringCollection, collection); + container.ConfigureComponent(DependencyLifecycle.InstancePerCall) .ConfigureProperty(p => p.ConnectionString, connectionString); @@ -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(DependencyLifecycle.InstancePerCall)