A simple example of connecting to a broker:
ConnectionFactory factory = new ConnectionFactory(); // // The next six lines are optional: factory.UserName = ConnectionFactory.DefaultUser; factory.Password = ConnectionFactory.DefaultPass; factory.VirtualHost = ConnectionFactory.DefaultVHost; factory.HostName = hostName; factory.Port = AmqpTcpEndpoint.UseDefaultPort; // IConnection conn = factory.CreateConnection(); // IModel ch = conn.CreateModel(); // // ... use ch's IModel methods ... // ch.Close(Constants.ReplySuccess, "Closing the channel"); conn.Close(Constants.ReplySuccess, "Closing the connection");
The same example, written more compactly with AMQP URIs:
ConnectionFactory factory = new ConnectionFactory(); factory.Uri = "amqp://localhost"; IConnection conn = factory.CreateConnection(); ...
Please see also the API overview and tutorial in the User Guide.
Note that the Uri property takes a string representation of an AMQP URI. Omitted URI parts will take default values. The host part of the URI cannot be omitted and URIs of the form "amqp://foo/" (note the trailling slash) also represent the default virtual host. The latter issue means that virtual hosts with an empty name are not addressable.