IConnection.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. using System;
  18. using System.Threading.Tasks;
  19. namespace Apache.NMS
  20. {
  21. /// <summary>
  22. /// The mode used to acknowledge messages after they are consumed
  23. /// </summary>
  24. public enum AcknowledgementMode
  25. {
  26. /// <summary>
  27. /// With this acknowledgment mode, the session will not
  28. /// acknowledge receipt of a message since the broker assumes
  29. /// successful receipt of a message after the onMessage handler
  30. /// has returned without error.
  31. /// </summary>
  32. AutoAcknowledge,
  33. /// <summary>
  34. /// With this acknowledgment mode, the session automatically
  35. /// acknowledges a client's receipt of a message either when
  36. /// the session has successfully returned from a call to receive
  37. /// or when the message listener the session has called to
  38. /// process the message successfully returns. Acknowlegements
  39. /// may be delayed in this mode to increase performance at
  40. /// the cost of the message being redelivered this client fails.
  41. /// </summary>
  42. DupsOkAcknowledge,
  43. /// <summary>
  44. /// With this acknowledgment mode, the client acknowledges a
  45. /// consumed message by calling the message's acknowledge method.
  46. /// This acknowledgement acknowledges the given message and all
  47. /// unacknowedged messages that have preceeded it for the session
  48. /// in which the message was delivered.
  49. /// </summary>
  50. ClientAcknowledge,
  51. /// <summary>
  52. /// Messages will be consumed when the transaction commits.
  53. /// </summary>
  54. Transactional,
  55. /// <summary>
  56. /// With this acknowledgment mode, the client acknowledges a
  57. /// consumed message by calling the message's acknowledge method.
  58. /// This acknowledgement mode allows the client to acknowledge a
  59. /// single message. This mode is not required to be supported by
  60. /// all NMS providers, however the provider should throw an appropriate
  61. /// exception to indicate that the mode is unsupported.
  62. /// </summary>
  63. IndividualAcknowledge
  64. }
  65. /// <summary>
  66. /// A delegate that can receive transport level exceptions.
  67. /// </summary>
  68. public delegate void ExceptionListener(Exception exception);
  69. /// <summary>
  70. /// A delegate that is used by Fault tolerant NMS Implementation to notify their
  71. /// clients that the Connection is not currently active to due some error.
  72. /// </summary>
  73. public delegate void ConnectionInterruptedListener();
  74. /// <summary>
  75. /// A delegate that is used by Fault tolerant NMS Implementation to notify their
  76. /// clients that the Connection that was interrupted has now been restored.
  77. /// </summary>
  78. public delegate void ConnectionResumedListener();
  79. /// <summary>
  80. /// Represents a connection with a message broker
  81. /// </summary>
  82. public interface IConnection : IDisposable, IStartable, IStoppable
  83. {
  84. /// <summary>
  85. /// Creates a new session to work on this connection
  86. /// </summary>
  87. ISession CreateSession();
  88. /// <summary>
  89. /// Creates a new session to work on this connection
  90. /// </summary>
  91. ISession CreateSession(AcknowledgementMode acknowledgementMode);
  92. /// <summary>
  93. /// Creates a new session to work on this connection
  94. /// </summary>
  95. Task<ISession> CreateSessionAsync();
  96. /// <summary>
  97. /// Creates a new session to work on this connection
  98. /// </summary>
  99. Task<ISession> CreateSessionAsync(AcknowledgementMode acknowledgementMode);
  100. /// <summary>
  101. /// Closes the connection.
  102. /// </summary>
  103. void Close();
  104. /// <summary>
  105. /// Closes the connection.
  106. /// </summary>
  107. Task CloseAsync();
  108. /// <summary>
  109. /// An asynchronous listener which can be notified if an error occurs
  110. /// </summary>
  111. event ExceptionListener ExceptionListener;
  112. /// <summary>
  113. /// An asynchronous listener that is notified when a Fault tolerant connection
  114. /// has been interrupted.
  115. /// </summary>
  116. event ConnectionInterruptedListener ConnectionInterruptedListener;
  117. /// <summary>
  118. /// An asynchronous listener that is notified when a Fault tolerant connection
  119. /// has been resumed.
  120. /// </summary>
  121. event ConnectionResumedListener ConnectionResumedListener;
  122. /// <summary>
  123. /// A Delegate that is called each time a Message is dispatched to allow the client to do
  124. /// any necessary transformations on the received message before it is delivered. The
  125. /// Connection sets the provided delegate instance on each Session it creates which then
  126. /// passes that along to the Consumers it creates.
  127. /// </summary>
  128. ConsumerTransformerDelegate ConsumerTransformer { get; set; }
  129. /// <summary>
  130. /// A delegate that is called each time a Message is sent from this Producer which allows
  131. /// the application to perform any needed transformations on the Message before it is sent.
  132. /// The Connection sets the provided delegate instance on each Session it creates which then
  133. /// passes that along to the Producer it creates.
  134. /// </summary>
  135. ProducerTransformerDelegate ProducerTransformer { get; set; }
  136. #region Attributes
  137. /// <summary>
  138. /// The default timeout for network requests.
  139. /// </summary>
  140. TimeSpan RequestTimeout { get; set; }
  141. /// <summary>
  142. /// The default acknowledgement mode
  143. /// </summary>
  144. AcknowledgementMode AcknowledgementMode { get; set; }
  145. /// <summary>
  146. /// Sets the unique clienet ID for this connection before Start() or returns the
  147. /// unique client ID after the connection has started
  148. /// </summary>
  149. string ClientId { get; set; }
  150. /// <summary>
  151. /// Get/or set the redelivery policy for this connection.
  152. /// </summary>
  153. IRedeliveryPolicy RedeliveryPolicy { get; set; }
  154. /// <summary>
  155. /// Gets the Meta Data for the NMS Connection instance.
  156. /// </summary>
  157. IConnectionMetaData MetaData { get; }
  158. #endregion
  159. #region Connection Management methods
  160. /// <summary>
  161. /// For a long running Connection that creates many temp destinations
  162. /// this method will close and destroy all previously created temp
  163. /// destinations to reduce resource consumption. This can be useful
  164. /// when the Connection is pooled or otherwise used for long periods
  165. /// of time. Only locally created temp destinations should be removed
  166. /// by this call.
  167. /// NOTE: This is an optional operation and for NMS providers that
  168. /// do not support this functionality the method should just return
  169. /// without throwing any exceptions.
  170. /// </summary>
  171. void PurgeTempDestinations();
  172. #endregion
  173. }
  174. }