protected async Task ConsumerOnReceived(object sender, BasicDeliverEventArgs @event) { var deliveryEvents = new DeliveryEvents(); var body = @event.Body.ToArray().Deserialize <TModel>(); if (OnConsumed != null) { await OnConsumed(body, deliveryEvents); if (deliveryEvents.Acknowledge) { Model.BasicAck(@event.DeliveryTag, false); } else { Model.BasicNack(@event.DeliveryTag, false, deliveryEvents.Requeue); } } deliveryEvents = await Mediator.Send(body); if (deliveryEvents.Acknowledge) { Model.BasicAck(@event.DeliveryTag, false); } else { Model.BasicNack(@event.DeliveryTag, false, deliveryEvents.Requeue); } }
public static async Task ProcessDeliveryStatusQueue( [QueueTrigger(DELIVERY_STATUS_QUEUE)] string deliveryStatusQueue, [Table(EMAIL_BLOCKED)] IAsyncCollector <EmailBlocked> tbEmailBlocked, [Table(EMAIL_TRACK)] CloudTable tbEmailTrack, int dequeueCount, ILogger log) { try { log.LogInformation($"New status to update. Dequeue count for this item: {dequeueCount}."); var deliveryStatusList = JsonConvert.DeserializeObject <List <DeliveryWebHook> >(deliveryStatusQueue); foreach (var status in deliveryStatusList) { if (DeliveryEvents.Contains(status.Event)) { if (BlockerEvents.Contains(status.Event)) { log.LogInformation($"Blocking email {status.Email}..."); await EmailBlocker.Create(tbEmailBlocked, status.Email, JsonConvert.SerializeObject(status), status.Event); } //TODO: Add to a list of Delivery Events await EmailTracker.Update(tbEmailTrack, status.Email, status.TrackerId, status.Event, log, status.SgMessageId); } else if (EngagementEvents.Contains(status.Event)) { //TODO: Add to a list of Engagement Events await EmailTracker.Update(tbEmailTrack, status.Email, status.TrackerId, status.Event, log, status.SgMessageId); } else { throw new Exception($"Event not mapped {status.Event}."); } } } catch (Exception ex) { log.LogError("An error has occurred: {0}", ex); throw; } }
private Task QueueConsumerOnConsumed(TestPublishEmailModel arg1, DeliveryEvents arg2) { arg2.Acknowledge = true; _logger.LogInformation($"Consumed : {JsonSerializer.Serialize(arg1)}"); return(Task.CompletedTask); }