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.PortNumber = 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");
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 | |
ClientProperties |
Dictionary of client properties to be sent to the server |
| public const | |
DefaultChannelMax |
Default value for the desired maximum channel number, with zero meaning unlimited (value: 0) |
| public const | |
DefaultFrameMax |
Default value for the desired maximum frame size, with zero meaning unlimited (value: 0) |
| public const | |
DefaultHeartbeat |
Default value for desired heartbeat interval, in seconds, with zero meaning none (value: 0) |
| public const | |
DefaultPass |
Default password (value: "guest") |
| public const | |
DefaultUser |
Default user name (value: "guest") |
| public const | |
DefaultVHost |
Default virtual host (value: "/") |
| public | |
HostName |
The host to connect to |
| public | |
Password |
Password to use when authenticating to the server |
| public | |
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 | |
RequestedChannelMax |
Maximum channel number to ask for |
| public | |
RequestedFrameMax |
Frame-max parameter to ask for (in bytes) |
| public | |
RequestedHeartbeat |
Heartbeat setting to request (in seconds) |
| public | SslOption |
Ssl |
Ssl options setting |
| public | |
UserName |
Username to use when authenticating to the server |
| public | |
VirtualHost |
Virtual host to access during this connection |
| Flags | Type | Name | Summary |
|---|---|---|---|
| public | |
Address (rw)
|
(undocumented) |
| public | AmqpTcpEndpoint |
Endpoint (rw)
|
(undocumented) |
| Flags | Name | Summary |
|---|---|---|
| public | ConnectionFactory()
|
Construct a fresh instance, with all fields set to their respective defaults. |
| Flags | Name | Summary |
|---|---|---|
| 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 virtual | IConnection CreateConnection()
|
Create a connection to the specified endpoint No broker-originated redirects are permitted. |
public ConnectionFactory()
public virtual IConnection CreateConnection(int maxRedirects)
| Flags | public virtual | ||||
|---|---|---|---|---|---|
| Return type | IConnection |
||||
| Parameters |
|
public virtual IConnection CreateConnection()
| Flags | public virtual |
|---|---|
| Return type | IConnection |