Exemplo n.º 1
0
        /// <summary>
        /// Pulls a single item from the specified queue, or null if nothing was available.
        /// After completing the message processing, you must call Complete().
        /// </summary>
        public static async Task <QueueMessageHandle <TMessage> > Pull <TMessage>(this IEventBusQueue queue, int timeoutSeconds = 10)
            where TMessage : IEventBusMessage
        {
            var item = await queue.Pull(timeoutSeconds);

            if (item == null)
            {
                return(null);
            }

            return(item.As <TMessage>());
        }
Exemplo n.º 2
0
        /// <summary>
        /// Pulls a single item from the specified queue, or null if nothing was available.
        /// After completing the message processing, you must call Complete().
        /// </summary>
        public static async Task <QueueMessageHandle <TMessage> > Pull <TMessage>(this IEventBusQueue queue, int timeoutSeconds = 10)
            where TMessage : IEventBusMessage
        {
            var item = await queue.Pull(timeoutSeconds);

            if (item == null || item.RawMessage.IsEmpty())
            {
                return(null);
            }

            try
            {
                var message = JsonConvert.DeserializeObject <TMessage>(item.RawMessage);
                return(new QueueMessageHandle <TMessage>(item.RawMessage, item.MessageId, message, () => item.Complete()));
            }
            catch (Exception ex)
            {
                throw new Exception("Failed to deserialize event message to " + typeof(TMessage).FullName + ":\r\n" + item.RawMessage, ex);
            }
        }