MassTransit/MassTransit — Issue #46: BeginSendRequest timeouts, web
Author: haf
Created: 2011-11-07 16:47:50+00:00
State: open

```

[HttpGet]
public void IndexAsync(IndexViewModel model)
{
AsyncManager.OutstandingOperations.Increment();
AsyncManager.Parameters["pingMessage"] = model.PingMessage;

_logger.Info(string.Format("message {0}", model.PingMessage));

Guid requestId = CombGuid.Generate();
string ipAddress = Request.ServerVariables["REMOTE_ADDR"];

_bus.GetEndpoint(new Uri("rabbitmq://localhost/PingServer"))
.BeginSendRequest(new Ping(requestId),
_bus,
y => AsyncManager.OutstandingOperations.Decrement(),
null, x =>
{
x.Handle(
msg => AsyncManager.Sync(() => AsyncManager.Parameters["e"] = msg));
x.HandleTimeout(TimeSpan.FromSeconds(10),
() => AsyncManager.Sync(() => AsyncManager.Parameters["timeout"] = true));
});
}

public ActionResult IndexCompleted(string username, Pong e, string returnUrl, bool timeout,
IEnumerable> errors)
{
if (!ModelState.IsValid)
{
_logger.Info(string.Format("user {0} failed to login due incorrect information", username));
foreach (var error in errors)
{
ModelState.AddModelError(error.Item1, error.Item2);

TempData["ModelState"] = ModelState;
return RedirectToAction("Index");
}
}

if (timeout)
{
ModelState.AddModelError("timeout",
"Unfortunately the authentication service didn't have the good grace to respond on time "
+ "- unfortunately we seem to be overloaded right now, please try again right now...");

_logger.Warn("didn't succeed in authenticating the user in time - check server is up and running and not overloaded");

TempData["ModelState"] = ModelState;
return RedirectToAction("Timeout");
}

return RedirectToAction("Success");
}
```

And the endpoint just does:

```
class PingHandler
: Consumes.All
{
private static int _counter;

public void Consume(Ping message)
{
Console.WriteLine(string.Format("Got ping#{0}|{1}", Interlocked.Increment(ref _counter), message.CorrelationId));
Bus.Instance.Context(x => x.Respond(new Pong(message.CorrelationId)));
}
}
```