I am trying to connect to a Rabbit mqtt which is running on linux vm. I need to publish to it from another server using c# program which was not working. I get the below error
Unhandled exception. RabbitMQ.Client.Exceptions.BrokerUnreachableException: None of the specified endpoints were reachable
string ipAddress = "19.167.17.**";
string username = "admin";
string password = "admin";
ConnectionFactory factory = new ConnectionFactory();
factory.Uri = new Uri($"amqp://admin:rabbitmqtt@{ipAddress}:5672");
factory.ClientProvidedName = "Testing1";
IConnection cnn = factory.CreateConnection();
if (cnn.IsOpen)
{
Console.WriteLine("Connection to rabbitmq is successfull. . .");
IModel channel = cnn.CreateModel();
channel.ConfirmSelect();
string exchangeName = "DemoExchange";
string routingKey = "demo-routing-key";
string queueName = "DemoQueue";
channel.ExchangeDeclare(exchangeName, ExchangeType.Direct);
channel.QueueDeclare(queueName, false, false, false, null);
channel.QueueBind(queueName, exchangeName, routingKey, null);
string messagestring = $"Hello world -> testing {DateTime.Now.ToString("g")} Rabbit MqTT";
DateTime timestamp = DateTime.UtcNow;
string timestampAsString = timestamp.ToString("yyyy-MM-dd HH:mm:ss");
// Message properties
var properties = channel.CreateBasicProperties();
properties.Headers = new Dictionary<string, object>();
properties.Headers.Add("Timestamp", timestampAsString);
//properties.Headers.Add("Id", "JobReqID");
byte[] messageBodyBytes = Encoding.UTF8.GetBytes(messagestring);
channel.BasicPublish(exchangeName, routingKey, basicProperties: properties, messageBodyBytes); // publishes a message to RabbitMQ .
if (channel.WaitForConfirms(TimeSpan.FromSeconds(1)))
{
Console.WriteLine("Message Sent successfully");
}
else
{
Console.WriteLine("Error sending message");
}
channel.Close();
cnn.Dispose();
Above code I tried and it started to throw the exception as no endpoints where reachable
Could anyone help me to solve this issue. and I am unable to change the mqtt config. If I tried changing it I am unable to start the mqtt service.