private async Task Handle(StreamEntry streamEntry, JobData jobData) { //JobData jobData = ParseJobData(streamEntry); if (jobData == null) { return; } if (!string.IsNullOrEmpty(jobData.ErrorGroup) && _groupName != jobData.ErrorGroup) //是出错的任务需要重试,但不是该组的不处理 { return; } var isSuccess = await HandleMessage(jobData); if (!isSuccess && jobData.ErrorCount < _options.MaxErrorReTryCount) //需要重试 { var delaySecond = GetDelaySecond(jobData.ErrorCount); jobData.ErrorCount++; jobData.ErrorGroup = _groupName; await _redisStorage.EnqueueDealy(jobData, TimeSpan.FromSeconds(delaySecond)); _logger.LogInformation($"RedisMessageBus消费失败,topic:{jobData.Topic},{delaySecond}秒后将进行{jobData.ErrorCount }次重试"); } }
public async Task PublishDelayAsync(Type messageType, object message, TimeSpan delay) { AssertUtils.IsNotNull(message, "消息不能null"); if (delay <= TimeSpan.Zero) { await PublishAsync(messageType, message); return; } var topic = GetTopic(messageType); var jobData = JobData.CreateJobData(topic, _options.Serializer.Serialize(message)); var result = await _redisStorage.EnqueueDealy(jobData, delay); AssertUtils.IsTrue(result, $"redis生产者数据失败,topic:{topic}"); }