MassTransit Azure服务总线,设置定期计划

时间:2019-03-29 09:14:47

标签: azureservicebus masstransit azure-scheduler

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

如果是,是否有示例代码可用?

或者构建类似于Quartz Scheduler服务但以Azure Scheduler为目标的服务更好?

1 个答案:

答案 0 :(得分:0)

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

  1. Azure Logic应用程序(替换Azure计划程序-阅读here
  2. 天蓝色函数
  3. 网络工作

在Azure Logic应用中,您可以构建工作流以通过"recurrence" trigger迁移日期。

在Azure Functions中,可以使用计时器触发器并使用Azure Service Bus SDK / REST API编写自己的逻辑。您可以找到有关C#脚本的计时器触发器here的更多信息,但您也可以使用JS,F#等。 如果您要使用Azure Function,如果计划的时间是每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 Service Bus的.NET SDK,您可以找到引用here。如果您不熟悉Azure函数,则C#脚本函数将以其他方式稍微起作用。引用dll的方法不同。您可以找到它here

在谈到Azure Web作业时,它作为Azure Web应用程序的一部分运行。对于Azure Web Job,您也可以使用控制台应用程序模板编写webjob。您也可以使用上述相同的Azure Service Bus SDK来开发Web Job。查找Azure Web作业here的文档。