Interface IConnection
Main interface to an AMQP connection.
Namespace: RabbitMQ.Client
Assembly: RabbitMQ.Client.dll
Syntax
public interface IConnection : INetworkConnection, IDisposable
Remarks
Instances of IConnection are used to create fresh sessions/channels. The ConnectionFactory class is used to construct IConnection instances. Please see the documentation for ConnectionFactory for an example of usage. Alternatively, an API tutorial can be found in the User Guide.
Extends the IDisposable interface, so that the "using" statement can be used to scope the lifetime of a channel when appropriate.
Properties
| Edit this page View SourceChannelMax
The maximum channel number this connection supports (0 if unlimited). Usable channel numbers range from 1 to this number, inclusive.
Declaration
ushort ChannelMax { get; }
Property Value
Type | Description |
---|---|
ushort |
ClientProperties
A copy of the client properties that has been sent to the server.
Declaration
IDictionary<string, object> ClientProperties { get; }
Property Value
Type | Description |
---|---|
IDictionary<string, object> |
ClientProvidedName
Application-specific connection name, will be displayed in the management UI if RabbitMQ server supports it. This value doesn't have to be unique and cannot be used as a connection identifier, e.g. in HTTP API requests. This value is supposed to be human-readable.
Declaration
string ClientProvidedName { get; }
Property Value
Type | Description |
---|---|
string |
CloseReason
Returns null if the connection is still in a state where it can be used, or the cause of its closure otherwise.
Declaration
ShutdownEventArgs CloseReason { get; }
Property Value
Type | Description |
---|---|
ShutdownEventArgs |
Remarks
Applications should use the ConnectionShutdown event to avoid race conditions. The scenario to avoid is checking CloseReason, seeing it is null (meaning the IConnection was available for use at the time of the check), and interpreting this mistakenly as a guarantee that the IConnection will remain usable for a time. Instead, the operation of interest should simply be attempted: if the IConnection is not in a usable state, an exception will be thrown (most likely OperationInterruptedException, but may vary depending on the particular operation being attempted).
Endpoint
Retrieve the endpoint this connection is connected to.
Declaration
AmqpTcpEndpoint Endpoint { get; }
Property Value
Type | Description |
---|---|
AmqpTcpEndpoint |
FrameMax
The maximum frame size this connection supports (0 if unlimited).
Declaration
uint FrameMax { get; }
Property Value
Type | Description |
---|---|
uint |
Heartbeat
The current heartbeat setting for this connection (System.TimeSpan.Zero for disabled).
Declaration
TimeSpan Heartbeat { get; }
Property Value
Type | Description |
---|---|
TimeSpan |
IsOpen
Returns true if the connection is still in a state where it can be used. Identical to checking if CloseReason equal null.
Declaration
bool IsOpen { get; }
Property Value
Type | Description |
---|---|
bool |
KnownHosts
Returns the known hosts that came back from the broker in the connection.open-ok method at connection startup time. Null until the connection is completely open and ready for use.
Declaration
AmqpTcpEndpoint[] KnownHosts { get; }
Property Value
Type | Description |
---|---|
AmqpTcpEndpoint[] |
Protocol
The IProtocol this connection is using to communicate with its peer.
Declaration
IProtocol Protocol { get; }
Property Value
Type | Description |
---|---|
IProtocol |
ServerProperties
A dictionary of the server properties sent by the server while establishing the connection. This typically includes the product name and version of the server.
Declaration
IDictionary<string, object> ServerProperties { get; }
Property Value
Type | Description |
---|---|
IDictionary<string, object> |
ShutdownReport
Returns the list of ShutdownReportEntry objects that contain information about any errors reported while closing the connection in the order they appeared
Declaration
IList<ShutdownReportEntry> ShutdownReport { get; }
Property Value
Type | Description |
---|---|
IList<ShutdownReportEntry> |
Methods
| Edit this page View SourceAbort()
Abort this connection and all its channels.
Declaration
void Abort()
Remarks
Note that all active channels, sessions, and models will be closed if this method is called. In comparison to normal Close() method, Abort() will not throw IOException during closing connection. This method waits infinitely for the in-progress close operation to complete.
Abort(TimeSpan)
Abort this connection and all its channels and wait with a timeout for all the in-progress close operations to complete.
Declaration
void Abort(TimeSpan timeout)
Parameters
Type | Name | Description |
---|---|---|
TimeSpan | timeout |
Remarks
This method, behaves in a similar way as method Abort() with the only difference that it explictly specifies a timeout given for all the in-progress close operations to complete. If timeout is reached and the close operations haven't finished, then socket is forced to close.
To wait infinitely for the close operations to complete use Infinite.
Abort(ushort, string)
Abort this connection and all its channels.
Declaration
void Abort(ushort reasonCode, string reasonText)
Parameters
Type | Name | Description |
---|---|---|
ushort | reasonCode | |
string | reasonText |
Remarks
The method behaves in the same way as Abort(), with the only difference that the connection is closed with the given connection close code and message.
The close code (See under "Reply Codes" in the AMQP 0-9-1 specification)
A message indicating the reason for closing the connection
Abort(ushort, string, TimeSpan)
Abort this connection and all its channels and wait with a timeout for all the in-progress close operations to complete.
Declaration
void Abort(ushort reasonCode, string reasonText, TimeSpan timeout)
Parameters
Type | Name | Description |
---|---|---|
ushort | reasonCode | |
string | reasonText | |
TimeSpan | timeout |
Remarks
The method behaves in the same way as Abort(TimeSpan), with the only difference that the connection is closed with the given connection close code and message.
The close code (See under "Reply Codes" in the AMQP 0-9-1 specification).
A message indicating the reason for closing the connection.
Close()
Close this connection and all its channels.
Declaration
void Close()
Remarks
Note that all active channels, sessions, and models will be closed if this method is called. It will wait for the in-progress close operation to complete. This method will not return to the caller until the shutdown is complete. If the connection is already closed (or closing), then this method will do nothing. It can also throw IOException when socket was closed unexpectedly.
Close(TimeSpan)
Close this connection and all its channels and wait with a timeout for all the in-progress close operations to complete.
Declaration
void Close(TimeSpan timeout)
Parameters
Type | Name | Description |
---|---|---|
TimeSpan | timeout |
Remarks
Note that all active channels, sessions, and models will be closed if this method is called. It will wait for the in-progress close operation to complete with a timeout. If the connection is already closed (or closing), then this method will do nothing. It can also throw IOException when socket was closed unexpectedly. If timeout is reached and the close operations haven't finished, then socket is forced to close.
To wait infinitely for the close operations to complete use InfiniteTimeSpan.
Close(ushort, string)
Close this connection and all its channels.
Declaration
void Close(ushort reasonCode, string reasonText)
Parameters
Type | Name | Description |
---|---|---|
ushort | reasonCode | |
string | reasonText |
Remarks
The method behaves in the same way as Close(), with the only difference that the connection is closed with the given connection close code and message.
The close code (See under "Reply Codes" in the AMQP specification).
A message indicating the reason for closing the connection.
Close(ushort, string, TimeSpan)
Close this connection and all its channels and wait with a timeout for all the in-progress close operations to complete.
Declaration
void Close(ushort reasonCode, string reasonText, TimeSpan timeout)
Parameters
Type | Name | Description |
---|---|---|
ushort | reasonCode | |
string | reasonText | |
TimeSpan | timeout |
Remarks
The method behaves in the same way as Close(TimeSpan), with the only difference that the connection is closed with the given connection close code and message.
The close code (See under "Reply Codes" in the AMQP 0-9-1 specification).
A message indicating the reason for closing the connection.
Operation timeout.
CreateModel()
Create and return a fresh channel, session, and model.
Declaration
IModel CreateModel()
Returns
Type | Description |
---|---|
IModel |
HandleConnectionBlocked(string)
Handle incoming Connection.Blocked methods.
Declaration
void HandleConnectionBlocked(string reason)
Parameters
Type | Name | Description |
---|---|---|
string | reason |
HandleConnectionUnblocked()
Handle incoming Connection.Unblocked methods.
Declaration
void HandleConnectionUnblocked()
UpdateSecret(string, string)
This method updates the secret used to authenticate this connection. It is used when secrets have an expiration date and need to be renewed, like OAuth 2 tokens.
Declaration
void UpdateSecret(string newSecret, string reason)
Parameters
Type | Name | Description |
---|---|---|
string | newSecret | The new secret. |
string | reason | The reason for the secret update. |
Events
| Edit this page View SourceCallbackException
Signalled when an exception occurs in a callback invoked by the connection.
Declaration
event EventHandler<CallbackExceptionEventArgs> CallbackException
Event Type
Type | Description |
---|---|
EventHandler<CallbackExceptionEventArgs> |
Remarks
This event is signalled when a ConnectionShutdown handler throws an exception. If, in future, more events appear on IConnection, then this event will be signalled whenever one of those event handlers throws an exception, as well.
ConnectionBlocked
Declaration
event EventHandler<ConnectionBlockedEventArgs> ConnectionBlocked
Event Type
Type | Description |
---|---|
EventHandler<ConnectionBlockedEventArgs> |
ConnectionShutdown
Raised when the connection is destroyed.
Declaration
event EventHandler<ShutdownEventArgs> ConnectionShutdown
Event Type
Type | Description |
---|---|
EventHandler<ShutdownEventArgs> |
Remarks
If the connection is already destroyed at the time an event handler is added to this event, the event handler will be fired immediately.
ConnectionUnblocked
Declaration
event EventHandler<EventArgs> ConnectionUnblocked
Event Type
Type | Description |
---|---|
EventHandler<EventArgs> |