Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show discard with callbacks #4574

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -9,14 +9,15 @@ public class ObjectMessageHandler :
{
static ILog log = LogManager.GetLogger<ObjectMessageHandler>();

public Task Handle(ObjectMessage message, IMessageHandlerContext context)
public async Task Handle(ObjectMessage message, IMessageHandlerContext context)
{
log.Info("Message received, Returning");
var objectResponseMessage = new ObjectResponseMessage
{
Property = "PropertyValue"
};
return context.Reply(objectResponseMessage);
await Task.Delay(3000);
await context.Reply(objectResponseMessage);
}
}

Expand Down
24 changes: 21 additions & 3 deletions samples/callbacks/Callbacks_3/Sender/Program.cs
@@ -1,4 +1,5 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using NServiceBus;

Expand All @@ -11,6 +12,15 @@ static async Task Main()
endpointConfiguration.UsePersistence<LearningPersistence>();
endpointConfiguration.UseTransport<LearningTransport>();

endpointConfiguration.Recoverability().CustomPolicy((config, context) =>
{
if (context.Exception is InvalidOperationException invalidOperationException && invalidOperationException.Message.StartsWith("No handlers could be found"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (context.Exception is InvalidOperationException invalidOperationException && invalidOperationException.Message.StartsWith("No handlers could be found"))
if (context.Exception is InvalidOperationException invalidOperationException && invalidOperationException.Message.StartsWith("No handlers could be found", StringComparison.OrdinalIgnoreCase))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks ramon. The PR was only for demonstration purposes and I don't intend to bring it in or do you think this would be a valuable addition?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danielmarbach I think this should be the default behavior for callbacks. Can't we make it into an issue for a maintenance release or maybe add this to the callback docs as a snippet?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I gave it a stab, see #4582

{
return RecoverabilityAction.Discard("Callback no longer active");
}
return DefaultRecoverabilityPolicy.Invoke(config, context);
});

endpointConfiguration.MakeInstanceUniquelyAddressable("1");
endpointConfiguration.EnableCallbacks();

Expand Down Expand Up @@ -89,12 +99,20 @@ static async Task SendObjectMessage(IEndpointInstance endpointInstance)

#region SendObjectMessage

var tcs = new CancellationTokenSource(TimeSpan.FromSeconds(1));
var message = new ObjectMessage();
var sendOptions = new SendOptions();
sendOptions.SetDestination("Samples.Callbacks.Receiver");
var response = await endpointInstance.Request<ObjectResponseMessage>(message, sendOptions)
.ConfigureAwait(false);
Console.WriteLine($"Callback received with response property value:{response.Property}");
try
{
var response = await endpointInstance.Request<ObjectResponseMessage>(message, sendOptions, tcs.Token)
.ConfigureAwait(false);
Console.WriteLine($"Callback received with response property value:{response.Property}");
}
catch (OperationCanceledException)
{
}


#endregion
}
Expand Down