Esempio n. 1
0
        /// <summary>
        /// Receive a message from the specified queue
        /// </summary>
        /// <typeparam name="T">The type of message to receive</typeparam>
        /// <param name="sendReceive">The sendReceive instance</param>
        /// <param name="queue">The queue to receive from</param>
        /// <param name="onMessage">The synchronous function that handles the message</param>
        /// <param name="cancellationToken">The cancellation token</param>
        /// <returns>Consumer cancellation. Call Dispose to stop consuming</returns>
        public static IDisposable Receive <T>(
            this ISendReceive sendReceive,
            string queue,
            Action <T> onMessage,
            CancellationToken cancellationToken = default
            )
        {
            Preconditions.CheckNotNull(sendReceive, "sendReceive");

            return(sendReceive.Receive(queue, onMessage, c => { }, cancellationToken));
        }
Esempio n. 2
0
        /// <summary>
        /// Receive a message from the specified queue. Dispatch them to the given handlers
        /// </summary>
        /// <param name="sendReceive">The sendReceive instance</param>
        /// <param name="queue">The queue to take messages from</param>
        /// <param name="addHandlers">A function to add handlers</param>
        /// <param name="cancellationToken">The cancellation token</param>
        /// <returns>Consumer cancellation. Call Dispose to stop consuming</returns>
        public static IDisposable Receive(
            this ISendReceive sendReceive,
            string queue,
            Action <IReceiveRegistration> addHandlers,
            CancellationToken cancellationToken = default
            )
        {
            Preconditions.CheckNotNull(sendReceive, "sendReceive");

            return(sendReceive.Receive(
                       queue,
                       addHandlers,
                       c => { },
                       cancellationToken
                       ));
        }
Esempio n. 3
0
        /// <summary>
        /// Receive a message from the specified queue
        /// </summary>
        /// <typeparam name="T">The type of message to receive</typeparam>
        /// <param name="sendReceive">The sendReceive instance</param>
        /// <param name="queue">The queue to receive from</param>
        /// <param name="onMessage">The asynchronous function that handles the message</param>
        /// <param name="cancellationToken">The cancellation token</param>
        /// <returns>Consumer cancellation. Call Dispose to stop consuming</returns>
        public static IDisposable Receive <T>(
            this ISendReceive sendReceive,
            string queue,
            Func <T, Task> onMessage,
            CancellationToken cancellationToken = default
            )
        {
            Preconditions.CheckNotNull(sendReceive, "sendReceive");

            return(sendReceive.Receive <T>(
                       queue,
                       (m, c) => onMessage(m),
                       c => { },
                       cancellationToken
                       ));
        }
Esempio n. 4
0
        /// <summary>
        /// Receive a message from the specified queue
        /// </summary>
        /// <typeparam name="T">The type of message to receive</typeparam>
        /// <param name="sendReceive">The sendReceive instance</param>
        /// <param name="queue">The queue to receive from</param>
        /// <param name="onMessage">The synchronous function that handles the message</param>
        /// <param name="configure">Action to configure consumer with</param>
        /// <param name="cancellationToken">The cancellation token</param>
        /// <returns>Consumer cancellation. Call Dispose to stop consuming</returns>
        public static IDisposable Receive <T>(
            this ISendReceive sendReceive,
            string queue,
            Action <T> onMessage,
            Action <IConsumerConfiguration> configure,
            CancellationToken cancellationToken = default
            )
        {
            Preconditions.CheckNotNull(sendReceive, "sendReceive");

            var onMessageAsync = TaskHelpers.FromAction <T>((m, c) => onMessage(m));

            return(sendReceive.Receive(
                       queue,
                       onMessageAsync,
                       configure,
                       cancellationToken
                       ));
        }
Esempio n. 5
0
 public virtual IDisposable Receive <T>(string queue, Action <T> onMessage)
     where T : class
 {
     return(sendReceive.Receive(queue, onMessage));
 }
Esempio n. 6
0
 public IDisposable ReceiveAsync <T>(string queue, Func <T, Task> onMessage, Action <IConsumerConfiguration> configure = null) where T : class
 {
     return(sendReceive.Receive(queue, onMessage, configure));
 }