INMSProducer.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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.Collections;
  19. using System.Threading.Tasks;
  20. namespace Apache.NMS
  21. {
  22. /// <summary>
  23. /// An object capable of sending messages to some destination
  24. /// https://www.oracle.com/technical-resources/articles/java/jms20.html
  25. /// </summary>
  26. public interface INMSProducer : System.IDisposable
  27. {
  28. INMSProducer Send(IDestination destination, IMessage message);
  29. INMSProducer Send(IDestination destination, String body);
  30. INMSProducer Send(IDestination destination, IPrimitiveMap body);
  31. INMSProducer Send(IDestination destination, byte[] body);
  32. INMSProducer Send(IDestination destination, object body);
  33. Task<INMSProducer> SendAsync(IDestination destination, IMessage message);
  34. Task<INMSProducer> SendAsync(IDestination destination, String body);
  35. Task<INMSProducer> SendAsync(IDestination destination, IPrimitiveMap body);
  36. Task<INMSProducer> SendAsync(IDestination destination, byte[] body);
  37. Task<INMSProducer> SendAsync(IDestination destination, object body);
  38. /// <summary>
  39. /// Provides access to the message properties (headers).
  40. /// </summary>
  41. IPrimitiveMap Properties { get; }
  42. /// <summary>
  43. /// Clears a message's properties.
  44. ///
  45. /// The message's header fields and body are not cleared.
  46. /// </summary>
  47. INMSProducer ClearProperties();
  48. /// <summary>
  49. /// The correlation ID used to correlate messages from conversations or long running business processes.
  50. /// </summary>
  51. string NMSCorrelationID { get; set; }
  52. /// <summary>
  53. /// The destination that the consumer of this message should send replies to
  54. /// </summary>
  55. IDestination NMSReplyTo { get; set; }
  56. /// <summary>
  57. /// Specifies that messages sent using this NMSProducer will
  58. /// have their NMSType header value set to the specified message type.
  59. /// </summary>
  60. string NMSType { get; set; }
  61. /// <summary>
  62. /// A delegate that is called each time a Message is sent from this Producer which allows
  63. /// the application to perform any needed transformations on the Message before it is sent.
  64. /// </summary>
  65. ProducerTransformerDelegate ProducerTransformer { get; set; }
  66. MsgDeliveryMode DeliveryMode { get; set; }
  67. TimeSpan DeliveryDelay { get; set; }
  68. TimeSpan TimeToLive { get; set; }
  69. TimeSpan RequestTimeout { get; set; }
  70. MsgPriority Priority { get; set; }
  71. bool DisableMessageID { get; set; }
  72. bool DisableMessageTimestamp { get; set; }
  73. //Method chaining setters
  74. //Allows message delivery options, headers, and properties to be configured using method chaining
  75. INMSProducer SetDeliveryDelay(TimeSpan deliveryDelay);
  76. INMSProducer SetTimeToLive(TimeSpan timeToLive);
  77. INMSProducer SetDeliveryMode(MsgDeliveryMode deliveryMode);
  78. INMSProducer SetDisableMessageID(bool value);
  79. INMSProducer SetDisableMessageTimestamp(bool value);
  80. INMSProducer SetNMSCorrelationID(string correlationID);
  81. INMSProducer SetNMSReplyTo(IDestination replyTo);
  82. INMSProducer SetNMSType(string type);
  83. INMSProducer SetPriority(MsgPriority priority);
  84. INMSProducer SetProperty(string name, bool value);
  85. INMSProducer SetProperty(string name, byte value);
  86. INMSProducer SetProperty(string name, double value);
  87. INMSProducer SetProperty(string name, float value);
  88. INMSProducer SetProperty(string name, int value);
  89. INMSProducer SetProperty(string name, long value);
  90. INMSProducer SetProperty(string name, short value);
  91. INMSProducer SetProperty(string name, char value);
  92. INMSProducer SetProperty(string name, string value);
  93. INMSProducer SetProperty(string name, byte[] value);
  94. INMSProducer SetProperty(string name, IList value);
  95. INMSProducer SetProperty(string name, IDictionary value);
  96. #region Factory methods to create messages
  97. /// <summary>
  98. /// Creates a new message with an empty body
  99. /// </summary>
  100. IMessage CreateMessage();
  101. /// <summary>
  102. /// Creates a new message with an empty body
  103. /// </summary>
  104. Task<IMessage> CreateMessageAsync();
  105. /// <summary>
  106. /// Creates a new text message with an empty body
  107. /// </summary>
  108. ITextMessage CreateTextMessage();
  109. /// <summary>
  110. /// Creates a new text message with an empty body
  111. /// </summary>
  112. Task<ITextMessage> CreateTextMessageAsync();
  113. /// <summary>
  114. /// Creates a new text message with the given body
  115. /// </summary>
  116. ITextMessage CreateTextMessage(string text);
  117. /// <summary>
  118. /// Creates a new text message with the given body
  119. /// </summary>
  120. Task<ITextMessage> CreateTextMessageAsync(string text);
  121. /// <summary>
  122. /// Creates a new Map message which contains primitive key and value pairs
  123. /// </summary>
  124. IMapMessage CreateMapMessage();
  125. /// <summary>
  126. /// Creates a new Map message which contains primitive key and value pairs
  127. /// </summary>
  128. Task<IMapMessage> CreateMapMessageAsync();
  129. /// <summary>
  130. /// Creates a new Object message containing the given .NET object as the body
  131. /// </summary>
  132. IObjectMessage CreateObjectMessage(object body);
  133. /// <summary>
  134. /// Creates a new Object message containing the given .NET object as the body
  135. /// </summary>
  136. Task<IObjectMessage> CreateObjectMessageAsync(object body);
  137. /// <summary>
  138. /// Creates a new binary message
  139. /// </summary>
  140. IBytesMessage CreateBytesMessage();
  141. /// <summary>
  142. /// Creates a new binary message
  143. /// </summary>
  144. Task<IBytesMessage> CreateBytesMessageAsync();
  145. /// <summary>
  146. /// Creates a new binary message with the given body
  147. /// </summary>
  148. IBytesMessage CreateBytesMessage(byte[] body);
  149. /// <summary>
  150. /// Creates a new binary message with the given body
  151. /// </summary>
  152. Task<IBytesMessage> CreateBytesMessageAsync(byte[] body);
  153. /// <summary>
  154. /// Creates a new stream message
  155. /// </summary>
  156. IStreamMessage CreateStreamMessage();
  157. /// <summary>
  158. /// Creates a new stream message
  159. /// </summary>
  160. Task<IStreamMessage> CreateStreamMessageAsync();
  161. #endregion
  162. /// <summary>
  163. /// Close the producer.
  164. /// </summary>
  165. void Close();
  166. /// <summary>
  167. /// Close the producer.
  168. /// </summary>
  169. Task CloseAsync();
  170. }
  171. }