Created
September 4, 2012 20:50
-
-
Save supersonicclay/3626290 to your computer and use it in GitHub Desktop.
Workaround MassTransit PublishRequest timeout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class BusExtensions | |
{ | |
/// <summary> | |
/// Sends a command and blocks while waiting for the result using a specified timeout. | |
/// </summary> | |
/// <param name="bus">The bus instance.</param> | |
/// <param name="command">The command to send.</param> | |
/// <param name="timeoutMilliseconds">The timout duration in milliseconds.</param> | |
public static void BasicRequest<TRequest>(this IServiceBus bus, TRequest command, TimeSpan timeOut) where TRequest : class | |
{ | |
Thread t = new Thread(() => PerformRequest<TRequest>(bus, command, timeOut)); | |
t.Start(); | |
t.Join(); | |
} | |
private static void PerformRequest<TRequest>(IServiceBus bus, TRequest command, TimeSpan timeOut) where TRequest : class | |
{ | |
bus.PublishRequest(command, requestConfig => | |
{ | |
requestConfig.Handle<SuccessResponse>(message => { /* TODO: handle */ }); | |
requestConfig.SetTimeout(timeOut); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment