The following is part of a Rabbitmq consumer application that's built as a windows form in visual studio 2013. This form connects to an exchange that was set up in another program and listens for messages sent through one of three routing keys: "info", "error", and "warning". The user chooses which of those routing keys they would like to listen to by checking them on the windows form and then clicking the listen button.
private void listenButton_Click(object sender, EventArgs e)
{
var factory = new ConnectionFactory() { HostName = "localhost" };
using (var connection = factory.CreateConnection())
using (var channel = connection.CreateModel())
{
channel.ExchangeDeclare("direct_logs", "direct");
var queueName = channel.QueueDeclare().QueueName;
if (infoCheckBox.Checked)
{
channel.QueueBind(queueName, "direct_logs", "info");
}
if (errorCheckBox.Checked)
{
channel.QueueBind(queueName, "direct_logs", "error");
}
if (warningCheckBox.Checked)
{
channel.QueueBind(queueName, "direct_logs", "warning");
}
var consumer = new EventingBasicConsumer(channel);
consumer.Received += (model, ea) =>
{
var body = ea.Body;
var message = Encoding.UTF8.GetString(body);
messageTextBox.Text += "\n" + message;
};
channel.BasicConsume(queueName, true, consumer);
}
}
In order to be able to perform the method QueueBind, however, I need queueName. But the program always fails on the line var queueName = channel.QueueDeclare().QueueName;
. It always freezes for about 10 seconds and then comes up with a timeout exception. I had almost the exact same code work in a console application. Is there something different that I need to account for when using a windows form? Thanks in advance for your help.