INMSConsumer.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. /// An object capable of sending messages to some destination
  23. /// https://www.oracle.com/technical-resources/articles/java/jms20.html
  24. /// </summary>
  25. public interface INMSConsumer : System.IDisposable
  26. {
  27. /// <summary>
  28. /// Waits until a message is available and returns it
  29. /// </summary>
  30. IMessage Receive();
  31. /// <summary>
  32. /// Waits until a message is available and returns it
  33. /// </summary>
  34. Task<IMessage> ReceiveAsync();
  35. /// <summary>
  36. /// If a message is available within the timeout duration it is returned otherwise this method returns null
  37. /// </summary>
  38. IMessage Receive(TimeSpan timeout);
  39. /// <summary>
  40. /// If a message is available within the timeout duration it is returned otherwise this method returns null
  41. /// </summary>
  42. Task<IMessage> ReceiveAsync(TimeSpan timeout);
  43. /// <summary>
  44. /// Receives the next message if one is immediately available for delivery on the client side
  45. /// otherwise this method returns null. It is never an error for this method to return null, the
  46. /// time of Message availability varies so your client cannot rely on this method to receive a
  47. /// message immediately after one has been sent.
  48. /// </summary>
  49. IMessage ReceiveNoWait();
  50. T ReceiveBody<T>();
  51. Task<T> ReceiveBodyAsync<T>();
  52. T ReceiveBody<T>(TimeSpan timeout);
  53. Task<T> ReceiveBodyAsync<T>(TimeSpan timeout);
  54. T ReceiveBodyNoWait<T>();
  55. string MessageSelector { get; }
  56. /// <summary>
  57. /// A listener which can be used to consume messages
  58. /// </summary>
  59. event MessageListener Listener;
  60. /// <summary>
  61. /// An asynchronous listener which can be used to consume messages asynchronously
  62. /// </summary>
  63. //event AsyncMessageListener AsyncListener;
  64. /// <summary>
  65. /// Closes the message consumer.
  66. /// </summary>
  67. /// <remarks>
  68. /// Clients should close message consumers when they are not needed.
  69. /// This call blocks until a receive or message listener in progress has completed.
  70. /// A blocked message consumer receive call returns null when this message consumer is closed.
  71. /// </remarks>
  72. void Close();
  73. /// <summary>
  74. /// Closes the message consumer.
  75. /// </summary>
  76. /// <remarks>
  77. /// Clients should close message consumers when they are not needed.
  78. /// </remarks>
  79. Task CloseAsync();
  80. /// <summary>
  81. /// A Delegate that is called each time a Message is dispatched to allow the client to do
  82. /// any necessary transformations on the received message before it is delivered.
  83. /// </summary>
  84. ConsumerTransformerDelegate ConsumerTransformer { get; set; }
  85. }
  86. }