Skip to content

Instantly share code, notes, and snippets.

@supersonicclay
Created September 4, 2012 20:50
Show Gist options
  • Save supersonicclay/3626290 to your computer and use it in GitHub Desktop.
Save supersonicclay/3626290 to your computer and use it in GitHub Desktop.
Workaround MassTransit PublishRequest timeout
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