Access to local MQ broker blocked despite AccessRights.FullAccess
Created at 25 Feb 2021, 20:09
IC
Access to local MQ broker blocked despite AccessRights.FullAccess
25 Feb 2021, 20:09
The below snippet sends a message through RabbitMQ. It assumes the RabbitMQ server to be running with no authentication.
Inside the Main function of a simple C# program, this successfully sends the message and displays the result.
However, the same code used in the OnStart method of a Bot with AccessRights.FullAccess (Console.WriteLine replaced with Print) crashes with "BrokerUnreachableException: None of the specified endpoints were reachable".
How do I get my Bot to reach the broker?
using System;
using System.Text;
using RabbitMQ.Client;
using RabbitMQ.Client.Events;
namespace helloworld
{
class Program
{
static void Main(string[] args)
{
string queueName = "signal";
string exchangeName = "";
string routingKey = "";
var factory = new ConnectionFactory() { HostName = "localhost" };
using (var connection = factory.CreateConnection())
using (var channel = connection.CreateModel())
{
channel.QueueDeclare(queue: queueName,
durable: false,
exclusive: false,
autoDelete: false,
arguments: null);
string message = "Hello World!";
var body = Encoding.UTF8.GetBytes(message);
channel.BasicPublish(exchange: "",
routingKey: queueName,
basicProperties: null,
body: body);
Console.WriteLine(" [x] sent {0}", message);
}
}
}
}