I'm trying to implement a simple .NET 6 microservice with RabbitMQ using EasyNetQ.
I have 2 completely different projects in 2 completely different solutions and when I try to use EasyNetQ's Request/Response I am able to send the request, my responder receives it and I'm able to process it, however the original caller never gets a response back. I get a TaskCanceledException
in my RequestService.cs
saying: "A task was canceled."
RequestService.cs
var bus = RabbitHutch.CreateBus("host=localhost;timeout=120;username=guest;password=guest");
var req = new SendMessageRequestModel
{
SenderUsername = "me",
ReceiverUsername = "alsoMe",
DateSent = DateTime.Now,
Content = "message"
};
//This following line works and sends the request successfully.
var response = await bus.Rpc.RequestAsync<SendMessageRequestModel, Result<bool>>(req);
// However it does not receive a response and here is where I get the TaskCanceledException.
Console.WriteLine("Response is:" + response.IsSuccessful);
Console.ReadLine();
bus.Dispose();
Here is the ReceiverService.cs
var bus = RabbitHutch.CreateBus("host=localhost;timeout=120;username=guest;password=guest");
await bus.Rpc.RespondAsync<SendMessageRequestModel, Result<bool>>(req =>
{
Console.WriteLine("Request made at: " + DateTime.UtcNow);
// Breakpoint here works.
return Result<bool>.Success(true);
});
Console.ReadLine();
bus.Dispose();
Here is the exception:
System.Threading.Tasks.TaskCanceledException: A task was canceled.
at EasyNetQ.DefaultRpc.RequestAsync[TRequest,TResponse](TRequest request, Action`1 configure, CancellationToken cancellationToken)
at Program.<Main>$(String[] args) in D:\Other\TempMQReceiver\temp\TempSender\TempSender\Program.cs:line 14
at Program.<Main>(String[] args)