【发布时间】:2018-10-25 18:02:14
【问题描述】:
我现在有一个在服务总线触发器(队列触发器)上运行并输出 SendGridMessage 的天蓝色函数。诀窍是在函数成功发送 sendgrid 消息后,我需要在我的 blob 存储中进行一些清理,但似乎我无法确定函数是否成功,直到它超出范围。
我目前正在尝试将需要清理的消息推送到清理队列并在尝试捕获后处理它,但我认为我仍然遇到同样的问题。该函数可能成功,然后在 SendGrid 输出上失败,消息将被清理但被扔回队列以在此函数上重新处理并失败。呵呵。
队列触发和 Sendgrid 输出
[FunctionName("ProcessEmail")]
public static void Run([ServiceBusTrigger("email-queue-jobs", AccessRights.Manage,
Connection = "MicroServicesServiceBus")]OutgoingEmail outgoingEmail, TraceWriter log,
[ServiceBus("email-queue-cleanup", Connection = "MicroServicesServiceBus",
EntityType = Microsoft.Azure.WebJobs.ServiceBus.EntityType.Queue)] IAsyncCollector<OutgoingEmail> cleanupEmailQueue,
[SendGrid] out SendGridMessage message)
{
try
{
log.Info($"Attempting to send the email {outgoingEmail.Id}");
message = SendgridHelper.ConvertToSendgridMessage(outgoingEmail);
log.Info("Successfully sent email:");
log.Info(JsonConvert.SerializeObject(outgoingEmail));
}
catch (Exception ex)
{
message = null;
throw ex;
}
// Add email to the cleanup queue
log.Info("Sending email to the cleanup queue.");
cleanupEmailQueue.AddAsync(outgoingEmail).Wait();
}
【问题讨论】:
标签: c# azure message-queue azure-functions sendgrid