public class ConnectionFactory

Summary

Main entry point to the RabbitMQ .NET AMQP client API. Constructs IConnection instances.

Remarks

A simple example of connecting to a broker:

                 ConnectionFactory factory = new ConnectionFactory();
                 //
                 // The next three lines are optional:
                 factory.Parameters.UserName = ConnectionParameters.DefaultUser;
                 factory.Parameters.Password = ConnectionParameters.DefaultPass;
                 factory.Parameters.VirtualHost = ConnectionParameters.DefaultVHost;
                 //
                 IProtocol protocol = Protocols.DefaultProtocol;
                 IConnection conn = factory.CreateConnection(protocol, hostName, portNumber);
                 //
                 IModel ch = conn.CreateModel();
                 ushort ticket = ch.AccessRequest("/data");
                 //
                 // ... use ch's IModel methods ...
                 //
                 ch.Close(200, "Closing the channel");
                 conn.Close(200, "Closing the connection");
            

Please see also the API overview and tutorial in the User Guide.

Some of the static methods described below take, as a convenience, a System.Uri instance representing an AMQP server address. The use of Uri here is not standardised - Uri is simply a convenient container for internet-address-like components. In particular, the Uri "Scheme" property is ignored: only the "Host" and "Port" properties are extracted.

Property Summary

Flags Type Name Summary
public ConnectionParameters Parameters (r)

Retrieve the parameters this factory uses to construct IConnection instances.

Constructor Summary

Flags Name Summary
public ConnectionFactory()

Constructs a ConnectionFactory with default values for Parameters.

Method Summary

Flags Name Summary
public IConnection CreateConnection(IProtocol version, Uri uri)

Create a connection to the endpoint specified.

public IConnection CreateConnection(IProtocol version, string hostName)

Create a connection to the endpoint specified. The port used is the default for the protocol.

public IConnection CreateConnection(string address)

Create a connection to the host (and optional port) specified, with the IProtocol from Protocols.FromEnvironment(). The format of the address string is the same as that accepted by AmqpTcpEndpoint.Parse().

public IConnection CreateConnection(Uri uri)

Create a connection to the endpoint specified, with the IProtocol from Protocols.FromEnvironment().

public virtual IConnection CreateConnection(int maxRedirects, AmqpTcpEndpoint[] endpoints)

Create a connection to the first available endpoint in the list provided. Up to a maximum of maxRedirects broker-originated redirects are permitted for each endpoint tried.

public virtual IConnection CreateConnection(AmqpTcpEndpoint[] endpoints)

Create a connection to the first available endpoint in the list provided. No broker-originated redirects are permitted.

public IConnection CreateConnection(IProtocol version, string hostName, int portNumber)

Create a connection to the endpoint specified.

Property Detail

public ConnectionParameters Parameters (r)

Summary

Retrieve the parameters this factory uses to construct IConnection instances.

Constructor Detail

ConnectionFactory

public ConnectionFactory()

Summary

Constructs a ConnectionFactory with default values for Parameters.

Method Detail

CreateConnection

public IConnection CreateConnection(IProtocol version, Uri uri)

Flags public
Return type IConnection
Parameters
Name Type
version IProtocol
uri Uri

Summary

Create a connection to the endpoint specified.

Remarks

Please see the class overview documentation for information about the Uri format in use.

Exception

CreateConnection

public IConnection CreateConnection(IProtocol version, string hostName)

Flags public
Return type IConnection
Parameters
Name Type
version IProtocol
hostName string

Summary

Create a connection to the endpoint specified. The port used is the default for the protocol.

Exception

CreateConnection

public IConnection CreateConnection(string address)

Flags public
Return type IConnection
Parameters
Name Type
address string

Summary

Create a connection to the host (and optional port) specified, with the IProtocol from Protocols.FromEnvironment(). The format of the address string is the same as that accepted by AmqpTcpEndpoint.Parse().

CreateConnection

public IConnection CreateConnection(Uri uri)

Flags public
Return type IConnection
Parameters
Name Type
uri Uri

Summary

Create a connection to the endpoint specified, with the IProtocol from Protocols.FromEnvironment().

Remarks

Please see the class overview documentation for information about the Uri format in use.

CreateConnection

public virtual IConnection CreateConnection(int maxRedirects, AmqpTcpEndpoint[] endpoints)

Flags public virtual
Return type IConnection
Parameters
Name Type
maxRedirects int
endpoints AmqpTcpEndpoint[]

Summary

Create a connection to the first available endpoint in the list provided. Up to a maximum of maxRedirects broker-originated redirects are permitted for each endpoint tried.

CreateConnection

public virtual IConnection CreateConnection(AmqpTcpEndpoint[] endpoints)

Flags public virtual
Return type IConnection
Parameters
Name Type
endpoints AmqpTcpEndpoint[]

Summary

Create a connection to the first available endpoint in the list provided. No broker-originated redirects are permitted.

CreateConnection

public IConnection CreateConnection(IProtocol version, string hostName, int portNumber)

Flags public
Return type IConnection
Parameters
Name Type
version IProtocol
hostName string
portNumber int

Summary

Create a connection to the endpoint specified.

Exception