public class ConnectionFactory

Nested types: ObtainSocket

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 six lines are optional:
                 factory.UserName = ConnectionFactory.DefaultUser;
                 factory.Password = ConnectionFactory.DefaultPass;
                 factory.VirtualHost = ConnectionFactory.DefaultVHost;
                 factory.Protocol = Protocols.FromEnvironment();
                 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.

Field Summary

Flags Type Name Summary
public AuthMechanismFactory[] AuthMechanisms

SASL auth mechanisms to use.

public IDictionary<string,object> ClientProperties

Dictionary of client properties to be sent to the server

public static AuthMechanismFactory[] DefaultAuthMechanisms

Default SASL auth mechanisms to use.

public const ushort DefaultChannelMax

Default value for the desired maximum channel number, with zero meaning unlimited (value: 0)

public const int DefaultConnectionTimeout

Default value for connection attempt timeout, in milliseconds

public const uint DefaultFrameMax

Default value for the desired maximum frame size, with zero meaning unlimited (value: 0)

public const ushort DefaultHeartbeat

Default value for desired heartbeat interval, in seconds, with zero meaning none (value: 0)

public const string DefaultPass

Default password (value: "guest")

public const string DefaultUser

Default user name (value: "guest")

public const string DefaultVHost

Default virtual host (value: "/")

public string HostName

The host to connect to

public string Password

Password to use when authenticating to the server

public int Port

The port to connect on. AmqpTcpEndpoint.UseDefaultPort indicates the default for the protocol should be used.

public IProtocol Protocol

The AMQP protocol to be used

public ushort RequestedChannelMax

Maximum channel number to ask for

public int RequestedConnectionTimeout

Timeout setting for connection attempts (in milliseconds)

public uint RequestedFrameMax

Frame-max parameter to ask for (in bytes)

public ushort RequestedHeartbeat

Heartbeat setting to request (in seconds)

public ConnectionFactory.ObtainSocket SocketFactory

Set custom socket options by providing a SocketFactory

public SslOption Ssl

Ssl options setting

public string UserName

Username to use when authenticating to the server

public string VirtualHost

Virtual host to access during this connection

Property Summary

Flags Type Name Summary
public AmqpTcpEndpoint Endpoint (rw)

The AMQP connection target

public Uri uri (w)

Set connection parameters using the amqp or amqps scheme

public string Uri (w)

Set connection parameters using the amqp or amqps scheme

Constructor Summary

Flags Name Summary
public ConnectionFactory()

Construct a fresh instance, with all fields set to their respective defaults.

Method Summary

Flags Name Summary
public AuthMechanismFactory AuthMechanismFactory(string[] mechs)

Given a list of mechanism names supported by the server, select a preferred mechanism, or null if we have none in common.

public virtual IConnection CreateConnection()

Create a connection to the specified endpoint No broker-originated redirects are permitted.

public virtual IConnection CreateConnection(int maxRedirects)

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 static TcpClient DefaultSocketFactory(AddressFamily addressFamily)

(undocumented)

Field Detail

public AuthMechanismFactory[] AuthMechanisms

Summary

SASL auth mechanisms to use.

public IDictionary<string,object> ClientProperties

Summary

Dictionary of client properties to be sent to the server

public static AuthMechanismFactory[] DefaultAuthMechanisms

Summary

Default SASL auth mechanisms to use.

public const ushort DefaultChannelMax

Summary

Default value for the desired maximum channel number, with zero meaning unlimited (value: 0)

public const int DefaultConnectionTimeout

Summary

Default value for connection attempt timeout, in milliseconds

public const uint DefaultFrameMax

Summary

Default value for the desired maximum frame size, with zero meaning unlimited (value: 0)

public const ushort DefaultHeartbeat

Summary

Default value for desired heartbeat interval, in seconds, with zero meaning none (value: 0)

public const string DefaultPass

Summary

Default password (value: "guest")

public const string DefaultUser

Summary

Default user name (value: "guest")

public const string DefaultVHost

Summary

Default virtual host (value: "/")

public string HostName

Summary

The host to connect to

public string Password

Summary

Password to use when authenticating to the server

public int Port

Summary

The port to connect on. AmqpTcpEndpoint.UseDefaultPort indicates the default for the protocol should be used.

public IProtocol Protocol

Summary

The AMQP protocol to be used

public ushort RequestedChannelMax

Summary

Maximum channel number to ask for

public int RequestedConnectionTimeout

Summary

Timeout setting for connection attempts (in milliseconds)

public uint RequestedFrameMax

Summary

Frame-max parameter to ask for (in bytes)

public ushort RequestedHeartbeat

Summary

Heartbeat setting to request (in seconds)

public ConnectionFactory.ObtainSocket SocketFactory

Summary

Set custom socket options by providing a SocketFactory

public SslOption Ssl

Summary

Ssl options setting

public string UserName

Summary

Username to use when authenticating to the server

public string VirtualHost

Summary

Virtual host to access during this connection

Property Detail

public AmqpTcpEndpoint Endpoint (rw)

Summary

The AMQP connection target

public Uri uri (w)

Summary

Set connection parameters using the amqp or amqps scheme

public string Uri (w)

Summary

Set connection parameters using the amqp or amqps scheme

Constructor Detail

ConnectionFactory

public ConnectionFactory()

Summary

Construct a fresh instance, with all fields set to their respective defaults.

Method Detail

AuthMechanismFactory

public AuthMechanismFactory AuthMechanismFactory(string[] mechs)

Flags public
Return type AuthMechanismFactory
Parameters
Name Type
mechs string[]

Summary

Given a list of mechanism names supported by the server, select a preferred mechanism, or null if we have none in common.

CreateConnection

public virtual IConnection CreateConnection()

Flags public virtual
Return type IConnection

Summary

Create a connection to the specified endpoint No broker-originated redirects are permitted.

CreateConnection

public virtual IConnection CreateConnection(int maxRedirects)

Flags public virtual
Return type IConnection
Parameters
Name Type
maxRedirects int

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.

DefaultSocketFactory

public static TcpClient DefaultSocketFactory(AddressFamily addressFamily)

Flags public static
Return type TcpClient
Parameters
Name Type
addressFamily AddressFamily