/// <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 }); }
/// <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 }); }
public async Task CollectSingleMetricAsync(Guid applicationId, string metricName, string metricNamespace, double value, long?timestamp) { if (timestamp == null || timestamp <= 0) { timestamp = TimeStampProvider.GetCurrentTimeStamp(TimePrecisionUnit.Seconds); } var redisDb = connectionMultiplexer.GetDatabase(); var metricKey = GetMetricKey(applicationId, metricName, metricNamespace); await loadedLuaScript.EvaluateAsync(redisDb, new { metricKey = (RedisKey)metricKey, timestamp, count = 1, min = value, max = value, sum = value, }); }
/// <summary> /// Asynchronously change the visibility timer of a single message. The time when the message will be visible again is calculated from the current time (now) + VisibilityTimer. /// /// returns 1 if successful, 0 if the message was not found /// </summary> public async Task <int> ChangeMessageVisibilityAsync(ChangeMessageVisibilityOptions options) { // todo : validate (qname, id, vt) var key = $"{this._options.Namespace}:{options.QueueName}"; var q = await this.GetQueue(options.QueueName); var res = await _changeMessageVisibility.EvaluateAsync( this.RedisClient, new { key = key, id = options.Id, newTimer = q.Timestamp + options.VisibilityTimer * 1000 } ); return((int)res); }
public Task <RedisResult> ScriptEvaluateAsync(LoadedLuaScript script, object parameters = null, CommandFlags flags = CommandFlags.None) { // TODO: The return value could contain prefixed keys. It might make sense to 'unprefix' those? return(script.EvaluateAsync(Inner, parameters, Prefix, flags)); }