Reputation: 1
I'm trying to create a basic example of rabitMQ messaging using EasynetQ lib in C#. when I do this on localhost it is working fine, but when I try to connect to a rabbitmq server on a different machine, I get a Taskcanceled exception when calling the subscribe metod. I'm using .net 7.0 with easynetQ 7.5.5 here is my publisher code:
using EasyNetQ;
using RabbitMQLearning.Shared.Messages;
var counter = 0;
using var bus = RabbitHutch.CreateBus("host=webdev;port=5672;username=usr;password=pwd");
var Timer = new Timer(PublishMessage, state:null,dueTime:0,period: (int) new TimeSpan(0,0,1).TotalMilliseconds);
await Task.Delay(Timeout.Infinite);
void PublishMessage(object state)
{
var message = new BasicMessage {
Id= counter,
Text = $"Hello {counter} from the rabbit hole"
};
bus.PubSub.Publish(message);
Console.WriteLine($"{DateTime.Now.ToString("HH:mm:ss:fff")} Message {counter} sent");
counter++;
}
the subscriber:
using EasyNetQ;
using RabbitMQLearning.Shared.Messages;
using var bus = RabbitHutch.CreateBus("host=webdev;port=5672;username=usr;password=pwdx");
bus.PubSub.Subscribe<BasicMessage>("MadHatter", SubscribeMessage);
Console.WriteLine("subscribed");
await Task.Delay(Timeout.Infinite);
Task SubscribeMessage(BasicMessage message) {
Console.WriteLine($"{DateTime.Now.ToString("HH:mm:ss:fff")} {message.Id} heard");
return Task.CompletedTask;
}
and the message object:
namespace RabbitMQLearning.Shared.Messages {
public class BasicMessage {
public int Id { get; set; }
public string Text { get; set; }
}
}
After a few seconds I get a TaskCanceledException on the subscribe<BasicMessage>
call.
the subscribem consolemessage was not hit at all
What am I missing here?
Upvotes: 0
Views: 287
Reputation: 1
Okay it was a silly bannapeel, it was not able to resolve the server name in the connection string. if I use an FQDN or an IP address in the host part, then it's works just fine.
Upvotes: 0