Callback Changes in Version 6

Component: Callbacks

The synchronous request-response feature, also known as Callbacks., has been moved from the NServiceBus core to the separate NServiceBus.Callbacks NuGet package. That package must be used in order to use the callback functionality in Version 6.

The API was also modified. Version 6 API is asynchronous by default and allows to easily access the response message. It is no longer possible to use callbacks inside handlers or sagas, because extension methods are only available on the message session. The differences in the API are fully covered in Callbacks.

The NServiceBus.Callbacks package has to be referenced only by the requesting endpoint. The responding endpoint only need NServiceBus.Callbacks if it replies with int or enum types.

1.x NServiceBus.Callbacks
var message = new RequestMessage();
var response = await endpoint.Request<ResponseMessage>(message)
5.x NServiceBus
var requestMessage = new RequestMessage();
        callback: asyncResult =>
            var localResult = (CompletionResult) asyncResult.AsyncState;
            var response = (ResponseMessage) localResult.Messages[0];
        state: null);

In order to use callbacks, the endpoint needs to be uniquely addressable:

1.x NServiceBus.Callbacks
var instanceDiscriminator = ConfigurationManager.AppSettings["InstanceId"];
This ID should never be hardcoded, e.g. it can be read from the configuration file or from the environment (e.g. role ID in Azure), so that it can be changed without code changes and redeployment.

Last modified