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.
| Flags | Type | Name | Summary |
|---|---|---|---|
| public |
ConnectionParameters
|
Parameters
(r)
|
Retrieve the parameters this factory uses to construct IConnection instances. |
| Flags | Name | Summary |
|---|---|---|
| public |
ConnectionFactory()
|
Constructs a ConnectionFactory with default values for Parameters. |
| 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. |
public
ConnectionFactory()
public
IConnection CreateConnection(IProtocol version, Uri uri)
| Flags | public | ||||||
|---|---|---|---|---|---|---|---|
| Return type |
IConnection
|
||||||
| Parameters |
|
public
IConnection CreateConnection(IProtocol version, string hostName)
| Flags | public | ||||||
|---|---|---|---|---|---|---|---|
| Return type |
IConnection
|
||||||
| Parameters |
|
public
IConnection CreateConnection(string address)
| Flags | public | ||||
|---|---|---|---|---|---|
| Return type |
IConnection
|
||||
| Parameters |
|
public
IConnection CreateConnection(Uri uri)
| Flags | public | ||||
|---|---|---|---|---|---|
| Return type |
IConnection
|
||||
| Parameters |
|
public virtual
IConnection CreateConnection(int maxRedirects, AmqpTcpEndpoint[] endpoints)
| Flags | public virtual | ||||||
|---|---|---|---|---|---|---|---|
| Return type |
IConnection
|
||||||
| Parameters |
|
public virtual
IConnection CreateConnection(AmqpTcpEndpoint[] endpoints)
| Flags | public virtual | ||||
|---|---|---|---|---|---|
| Return type |
IConnection
|
||||
| Parameters |
|
public
IConnection CreateConnection(IProtocol version, string hostName, int portNumber)
| Flags | public | ||||||||
|---|---|---|---|---|---|---|---|---|---|
| Return type |
IConnection
|
||||||||
| Parameters |
|