如何将消息放入死信并在 azure 函数中经过一段时间后对其进行处理
How to put message into dead-letter and process it after some interval in azure function
我有azure function which trigger when we ave new message into service bus topic.
在 azure 函数中,我 checked the customer api is available or not
通过调用它并检查它 status code
。
如果状态代码为 200,我需要处理该消息,否则将此消息放入死信中,并在一段时间后客户 api 可用时处理所有死信消息。
public static class Function1
{
[FunctionName("Function1")]
public static void Run([ServiceBusTrigger("customer-order", "customer-order", Connection = "")]string mySbMsg, ILogger log)
{
// 1.call customer api to check it is available or not
// 2.if it is up and running then process the message else put message into dead-letter
// and after some interval when customer ai is available process dead-letter messages
log.LogInformation($"C# ServiceBus topic trigger function processed message: {mySbMsg}");
}
}
我可以使用 HTTPClient 调用 customer api
并处理消息。
but how to put message into dead-letter and How to execute dead-letter
after some interval when customer api is available ?
提议的流程将是
in azure function app which will trigger if new message is there into.
topic start step - Check api is available or down if api is available
process the current message if api is down then do not process
message here we have two choices
1a.put current message into dead letter
1b.put current message back into main but if we do this then again function app will trigger as its new message trigger based and start step will continue.
与其将其放入死信队列,更好的方法是 defer the message 一段时间。
If a message cannot be processed because a particular resource for
handling that message is temporarily unavailable but message
processing should not be summarily suspended, a way to put that
message on the side for a few minutes is to remember the
SequenceNumber in a scheduled message to be posted in a few minutes,
and re-retrieve the deferred message when the scheduled message
arrives.
有关如何在 Azure Functions v2 中执行延迟的示例,请参阅此 。请注意,输入绑定使用 Message
类型的消息,并且还使用注入的 MessageReceiver
。需要这些才能调用 DeferAsync
。服务总线触发器的模板代码将消息类型设置为字符串,因此您必须按照该答案中的描述更改签名。
关于延迟消息:
Deferred messages remain in the main queue along with all other active
messages (unlike dead-letter messages that live in a subqueue), but
they can no longer be received using the regular Receive/ReceiveAsync
functions. To retrieve a deferred message, its owner is responsible
for remembering the SequenceNumber as it defers it. Any receiver that
knows the sequence number of a deferred message can later receive the
message explicitly with Receive(sequenceNumber).
如何安排带有延迟消息序列号的消息,以便稍后处理延迟消息:
You can schedule messages either by setting the
ScheduledEnqueueTimeUtc property when sending a message through the
regular send path, or explicitly with the ScheduleMessageAsync API
我有azure function which trigger when we ave new message into service bus topic.
在 azure 函数中,我 checked the customer api is available or not
通过调用它并检查它 status code
。
如果状态代码为 200,我需要处理该消息,否则将此消息放入死信中,并在一段时间后客户 api 可用时处理所有死信消息。
public static class Function1
{
[FunctionName("Function1")]
public static void Run([ServiceBusTrigger("customer-order", "customer-order", Connection = "")]string mySbMsg, ILogger log)
{
// 1.call customer api to check it is available or not
// 2.if it is up and running then process the message else put message into dead-letter
// and after some interval when customer ai is available process dead-letter messages
log.LogInformation($"C# ServiceBus topic trigger function processed message: {mySbMsg}");
}
}
我可以使用 HTTPClient 调用 customer api
并处理消息。
but how to put message into dead-letter and How to execute dead-letter after some interval when customer api is available ?
提议的流程将是
in azure function app which will trigger if new message is there into.
topic start step - Check api is available or down if api is available
process the current message if api is down then do not process
message here we have two choices
1a.put current message into dead letter 1b.put current message back into main but if we do this then again function app will trigger as its new message trigger based and start step will continue.
与其将其放入死信队列,更好的方法是 defer the message 一段时间。
If a message cannot be processed because a particular resource for handling that message is temporarily unavailable but message processing should not be summarily suspended, a way to put that message on the side for a few minutes is to remember the SequenceNumber in a scheduled message to be posted in a few minutes, and re-retrieve the deferred message when the scheduled message arrives.
有关如何在 Azure Functions v2 中执行延迟的示例,请参阅此 Message
类型的消息,并且还使用注入的 MessageReceiver
。需要这些才能调用 DeferAsync
。服务总线触发器的模板代码将消息类型设置为字符串,因此您必须按照该答案中的描述更改签名。
关于延迟消息:
Deferred messages remain in the main queue along with all other active messages (unlike dead-letter messages that live in a subqueue), but they can no longer be received using the regular Receive/ReceiveAsync functions. To retrieve a deferred message, its owner is responsible for remembering the SequenceNumber as it defers it. Any receiver that knows the sequence number of a deferred message can later receive the message explicitly with Receive(sequenceNumber).
如何安排带有延迟消息序列号的消息,以便稍后处理延迟消息:
You can schedule messages either by setting the ScheduledEnqueueTimeUtc property when sending a message through the regular send path, or explicitly with the ScheduleMessageAsync API