Example #1
0
        /// <summary>
        /// Asynchronously receive the next message from the queue.
        /// </summary>
        public async Task <RsmqMessage> ReceiveMessageAsync(ReceiveMessageOptions options)
        {
            Validate(options, "QueueName");
            var q = await this.GetQueue(options.QueueName);

            options.VisibilityTimer = options.VisibilityTimer.HasValue ? options.VisibilityTimer.Value : q.VisibilityTimer;
            Validate(options);

            var res = await _receiveMessage.EvaluateAsync(
                this.RedisClient,
                new
            {
                key              = (RedisKey)$"{this._options.Namespace}:{options.QueueName}",
                timestamp        = q.Timestamp,
                timestampTimeout = q.Timestamp + options.VisibilityTimer * 1000
            }
                );

            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
            });
        }
Example #2
0
 /// <summary>
 /// Synchronously receive the next message from the queue.
 /// </summary>
 public RsmqMessage ReceiveMessage(ReceiveMessageOptions options)
 {
     return(ReceiveMessageAsync(options).ConfigureAwait(false).GetAwaiter().GetResult());
 }