MassTransit Azure Service Bus,设置定期计划



是否可以为通过服务总线上运行的 MassTransit 传递消息设置定期计划?

如果是这样,是否有任何可用的示例代码?

还是构建类似于 Quartz 计划程序服务但以 Azure 计划程序为目标的服务更好?

如果您使用的是 Azure,则有三个选项,

Azure
  1. 逻辑应用(替换 Azure 调度程序 - 在此处阅读)
  2. Azure Functions
  3. 网络作业

在 Azure 逻辑应用中,可以生成工作流以通过"定期"触发器迁移日期。

在 Azure 函数中,可以使用计时器触发器,并使用 Azure 服务总线 SDK/REST API 编写自己的逻辑。您可以在此处找到有关 C# 脚本的计时器触发器的详细信息,但您也可以使用 JS、F# 等。 如果您使用的是 Azure 函数,如果计划时间为每 5 分钟一次,则function.json将按如下方式编码

{
"schedule": "0 */5 * * * *",
"name": "myTimer",
"type": "timerTrigger",
"direction": "in"
}

该函数的代码如下所示

public static void Run(TimerInfo myTimer, ILogger log)
{
const string ServiceBusConnectionString = "<your_connection_string>";
const string QueueName = "<your_queue_name>";
static IQueueClient queueClient
if (myTimer.IsPastDue)
{
log.LogInformation("Timer is running late!");
}
queueClient = new QueueClient(ServiceBusConnectionString, QueueName);
// Your logic to read to write message
}

我正在使用适用于 Azure 服务总线的 .NET SDK,你可以在此处找到参考。如果你不熟悉 Azure 函数,C# 脚本函数的工作方式略有不同。引用 dll 的方法不同。你可以在这里找到它。

当涉及到Azure Web Jobs时,它作为Azure Web应用程序的一部分运行。对于 Azure Web 作业,还可以使用控制台应用程序模板编写 Web 作业。也可以使用上面提到的同一 Azure 服务总线 SDK 来开发 Web 作业。在此处查找 Azure Web 作业的文档。

最新更新