Exemplo n.º 1
0
        /// <summary>
        /// Asynchronously receive the next message from the queue and delete it.
        ///
        /// Important: This method deletes the message it receives right away. There is no way to receive the message again if something goes wrong while working on the message.
        ///
        /// returns null if no message is there
        /// </summary>
        public async Task <RsmqMessage> PopMessageAsync(PopMessageOptions options)
        {
            // todo: validate (qname)
            var key = $"{this._options.Namespace}:{options.QueueName}";
            var q   = await this.GetQueue(options.QueueName);

            var res = await _popMessage.EvaluateAsync(
                this.RedisClient,
                new
            {
                key       = key,
                timestamp = q.Timestamp
            }
                );

            var vals = (string[])res;

            if (vals.Length != 4)
            {
                return(null);
            }

            return(new RsmqMessage
            {
                Id = vals[0],
                Message = vals[1],
                ReceivedCount = int.Parse(vals[2]),
                FirstReceived = DateTimeOffset.FromUnixTimeMilliseconds(long.Parse(vals[3])).UtcDateTime,
                Sent = DateTimeOffset.FromUnixTimeMilliseconds(Base36.Decode(vals[0].Substring(0, 10)) / 1000).UtcDateTime
            });
        }
Exemplo n.º 2
0
 /// <summary>
 /// Synchronously receive the next message from the queue and delete it.
 ///
 /// Important: This method deletes the message it receives right away. There is no way to receive the message again if something goes wrong while working on the message.
 ///
 /// returns null if no message is there
 /// </summary>
 public RsmqMessage PopMessage(PopMessageOptions options)
 {
     return(PopMessageAsync(options).ConfigureAwait(false).GetAwaiter().GetResult());
 }