techspider
techspider

Reputation: 3410

Unable to connect to RabbitMQ on server

I have the below code that connects to RabbitMQ on my local machine but when I change Host name from localhost to my servername it fails and returns the error

var factory = new ConnectionFactory();
factory.UserName = "myuser";
factory.Password = "mypassword";
factory.VirtualHost = "/";
factory.Port = AmqpTcpEndpoint.UseDefaultPort;
factory.HostName = "localhost";

As soon as I change HostName as below, it returns error

factory.HostName = "myserver";

Exception: None of the specified endpoints were reachable

The AMQP operation was interrupted: AMQP close-reason, initiated by Library, code=0, text=\"End of stream\", classId=0, methodId=0, cause=System.IO.EndOfStreamException: Peer missed 2 heartbeats with heartbeat timeout set to 60 seconds

Upvotes: 0

Views: 6542

Answers (2)

jhilden
jhilden

Reputation: 12429

Instead of connecting this way, it's much easier to connect using a connection string like you would with sql.

Example C#:

var factory = new ConnectionFactory
{
    Uri = ConfigurationManager.ConnectionStrings["RabbitMQ"].ConnectionString,
    RequestedHeartbeat = 15,
    //every N seconds the server will send a heartbeat.  If the connection does not receive a heartbeat within
    //N*2 then the connection is considered dead.
    //suggested from http://public.hudl.com/bits/archives/2013/11/11/c-rabbitmq-happy-servers/
    AutomaticRecoveryEnabled = true
};
return factory.CreateConnection();

web.config or app.config

  <connectionStrings>
    <add name="RabbitMQ" connectionString="amqp://{username}:{password}@{servername}/{vhost}" />
  </connectionStrings>

Upvotes: 1

techspider
techspider

Reputation: 3410

On server, it looks like Host Name is configured different. My Admin looked at logs and looked at configuration and provided me with the Host Name on server.

var factory = new ConnectionFactory();
factory.UserName = "myuser";
factory.Password = "mypassword";
factory.VirtualHost = "/filestream";
factory.Port = AmqpTcpEndpoint.UseDefaultPort;
factory.HostName = "myserver";

Upvotes: 0

Related Questions