1 // This source code is dual-licensed under the Apache License, version
2 // 2.0, and the Mozilla Public License, version 1.1.
6 //---------------------------------------------------------------------------
7 // Copyright (C) 2007-2009 LShift Ltd., Cohesive Financial
8 // Technologies LLC., and Rabbit Technologies Ltd.
10 // Licensed under the Apache License, Version 2.0 (the "License");
11 // you may not use this file except in compliance with the License.
12 // You may obtain a copy of the License at
14 // http://www.apache.org/licenses/LICENSE-2.0
16 // Unless required by applicable law or agreed to in writing, software
17 // distributed under the License is distributed on an "AS IS" BASIS,
18 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 // See the License for the specific language governing permissions and
20 // limitations under the License.
21 //---------------------------------------------------------------------------
25 //---------------------------------------------------------------------------
26 // The contents of this file are subject to the Mozilla Public License
27 // Version 1.1 (the "License"); you may not use this file except in
28 // compliance with the License. You may obtain a copy of the License at
29 // http://www.rabbitmq.com/mpl.html
31 // Software distributed under the License is distributed on an "AS IS"
32 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
33 // License for the specific language governing rights and limitations
36 // The Original Code is The RabbitMQ .NET Client.
38 // The Initial Developers of the Original Code are LShift Ltd,
39 // Cohesive Financial Technologies LLC, and Rabbit Technologies Ltd.
41 // Portions created before 22-Nov-2008 00:00:00 GMT by LShift Ltd,
42 // Cohesive Financial Technologies LLC, or Rabbit Technologies Ltd
43 // are Copyright (C) 2007-2008 LShift Ltd, Cohesive Financial
44 // Technologies LLC, and Rabbit Technologies Ltd.
46 // Portions created by LShift Ltd are Copyright (C) 2007-2009 LShift
47 // Ltd. Portions created by Cohesive Financial Technologies LLC are
48 // Copyright (C) 2007-2009 Cohesive Financial Technologies
49 // LLC. Portions created by Rabbit Technologies Ltd are Copyright
50 // (C) 2007-2009 Rabbit Technologies Ltd.
52 // All Rights Reserved.
54 // Contributor(s): ______________________________________.
56 //---------------------------------------------------------------------------
58 using System.Collections;
59 using RabbitMQ.Client.Events;
61 namespace RabbitMQ.Client
63 ///<summary>Main interface to an AMQP connection.</summary>
66 /// Instances of IConnection are used to create fresh
67 /// sessions/channels. The ConnectionFactory class is used to
68 /// construct IConnection instances. Please see the documentation
69 /// for ConnectionFactory for an example of usage. Alternatively,
70 /// an API tutorial can be found in the User Guide.
73 /// Extends the IDisposable interface, so that the "using"
74 /// statement can be used to scope the lifetime of a channel when
78 public interface IConnection: IDisposable
80 ///<summary>Raised when the connection is destroyed.</summary>
82 /// If the connection is already destroyed at the time an
83 /// event handler is added to this event, the event handler
84 /// will be fired immediately.
86 event ConnectionShutdownEventHandler ConnectionShutdown;
88 ///<summary>Signalled when an exception occurs in a callback
89 ///invoked by the connection.</summary>
91 ///This event is signalled when a ConnectionShutdown handler
92 ///throws an exception. If, in future, more events appear on
93 ///IConnection, then this event will be signalled whenever one
94 ///of those event handlers throws an exception, as well.
96 event CallbackExceptionEventHandler CallbackException;
98 ///<summary>Retrieve the endpoint this connection is connected
100 AmqpTcpEndpoint Endpoint { get; }
102 ///<summary>The IProtocol this connection is using to
103 ///communicate with its peer.</summary>
104 IProtocol Protocol { get; }
106 ///<summary>The connection parameters used during construction
107 ///of this connection.</summary>
108 ConnectionParameters Parameters { get; }
110 ///<summary>The maximum channel number this connection
111 ///supports (0 if unlimited). Usable channel numbers
112 ///range from 1 to this number, inclusive.</summary>
113 ushort ChannelMax { get; }
115 ///<summary>The maximum frame size this connection supports (0
116 ///if unlimited).</summary>
117 uint FrameMax { get; }
119 ///<summary>The current heartbeat setting for this connection
120 ///(0 for disabled), in seconds.</summary>
121 ushort Heartbeat { get; }
123 ///<summary>Returns the known hosts that came back from the
124 ///broker in the connection.open-ok method at connection
125 ///startup time. Null until the connection is completely open
126 ///and ready for use.</summary>
127 AmqpTcpEndpoint[] KnownHosts { get; }
129 ///<summary>Returns null if the connection is still in a state
130 ///where it can be used, or the cause of its closure
131 ///otherwise.</summary>
134 /// Applications should use the ConnectionShutdown event to
135 /// avoid race conditions. The scenario to avoid is checking
136 /// CloseReason, seeing it is null (meaning the IConnection
137 /// was available for use at the time of the check), and
138 /// interpreting this mistakenly as a guarantee that the
139 /// IConnection will remain usable for a time. Instead, the
140 /// operation of interest should simply be attempted: if the
141 /// IConnection is not in a usable state, an exception will be
142 /// thrown (most likely OperationInterruptedException, but may
143 /// vary depending on the particular operation being
147 ShutdownEventArgs CloseReason { get; }
149 ///<summary>Returns true if the connection is still in a state
150 ///where it can be used. Identical to checking if CloseReason
151 ///== null.</summary>
154 ///<summary>If true, will close the whole connection as soon
155 ///as there are no channels open on it; if false, manual
156 ///connection closure will be required.</summary>
158 /// Don't set AutoClose to true before opening the first
159 /// channel, because the connection will be immediately closed
162 bool AutoClose { get; set; }
164 ///<summary>Create and return a fresh channel, session, and
166 IModel CreateModel();
168 ///<summary>Close this connection and all its channels.</summary>
170 ///Note that all active channels, sessions, and models will be
171 ///closed if this method is called. It will wait for the in-progress
172 ///close operation to complete. This method will not return to the caller
173 ///until the shutdown is complete. If the connection is already closed
174 ///(or closing), then this method will throw AlreadyClosedException.
175 ///It can also throw IOException when socket was closed unexpectedly.
179 ///<summary>Close this connection and all its channels.</summary>
181 ///The method behaves in the same way as Close(), with the only
182 ///difference that the connection is closed with the given connection
183 ///close code and message.
185 ///The close code (See under "Reply Codes" in the AMQP specification)
188 ///A message indicating the reason for closing the connection
191 void Close(ushort reasonCode, string reasonText);
193 ///<summary>Close this connection and all its channels
194 ///and wait with a timeout for all the in-progress close operations
198 ///Note that all active channels, sessions, and models will be
199 ///closed if this method is called. It will wait for the in-progress
200 ///close operation to complete with a timeout. If the connection is
201 ///already closed (or closing), then this method will throw
202 ///AlreadyClosedException.
203 ///It can also throw IOException when socket was closed unexpectedly.
204 ///If timeout is reached and the close operations haven't finished,
205 ///then socket is forced to close.
207 ///To wait infinitely for the close operations to complete use
211 void Close(int timeout);
213 ///<summary>Close this connection and all its channels
214 ///and wait with a timeout for all the in-progress close operations
218 ///The method behaves in the same way as Close(int timeout), with the only
219 ///difference that the connection is closed with the given connection
220 ///close code and message.
222 ///The close code (See under "Reply Codes" in the AMQP specification)
225 ///A message indicating the reason for closing the connection
228 void Close(ushort reasonCode, string reasonText, int timeout);
230 ///<summary>Abort this connection and all its channels.</summary>
232 ///Note that all active channels, sessions, and models will be
233 ///closed if this method is called.
234 ///In comparison to normal Close() method, Abort() will not throw
235 ///AlreadyClosedException or IOException during closing connection.
236 ///This method waits infinitely for the in-progress close operation
241 ///<summary>Abort this connection and all its channels.</summary>
243 ///The method behaves in the same way as Abort(), with the only
244 ///difference that the connection is closed with the given connection
245 ///close code and message.
247 ///The close code (See under "Reply Codes" in the AMQP specification)
250 ///A message indicating the reason for closing the connection
253 void Abort(ushort reasonCode, string reasonText);
256 ///Abort this connection and all its channels and wait with a
257 ///timeout for all the in-progress close operations to complete.
260 ///This method, behaves in a similar way as method Abort() with the
261 ///only difference that it explictly specifies the timeout given
262 ///for all the in-progress close operations to complete.
263 ///If timeout is reached and the close operations haven't finished,
264 ///then socket is forced to close.
266 ///To wait infinitely for the close operations to complete use
270 void Abort(int timeout);
273 ///Abort this connection and all its channels and wait with a
274 ///timeout for all the in-progress close operations to complete.
277 ///The method behaves in the same way as Abort(timeout), with the only
278 ///difference that the connection is closed with the given connection
279 ///close code and message.
281 ///The close code (See under "Reply Codes" in the AMQP specification)
284 ///A message indicating the reason for closing the connection
287 void Abort(ushort reasonCode, string reasonText, int timeout);
289 ///<summary>Returns the list of ShutdownReportEntry objects that
290 ///contain information about any errors reported while closing the
291 ///connection in the order they appeared</summary>
292 IList ShutdownReport { get; }