0

Is it possible to set a recurring schedule for message delivery via MassTransit running on Service Bus?

If so, is there any example code available?

Or is it better to build a service similar to a Quartz Scheduler service but target Azure Scheduler?

robs
  • 840
  • 10
  • 15
  • It occurs to me it might be easier to use Azure Scheduler to kick off a function that in turn sends a message to Service Bus. Then would not need to think about the message structure for MassTransit. If that is making sense. – robs Mar 29 '19 at 09:51
  • Using Azure Scheduler to trigger the function would be a good approach. – Chris Patterson Mar 29 '19 at 12:47

1 Answers1

0

If you are using Azure, you have three options,

  1. Azure Logic Apps (replacing Azure scheduler - read here)
  2. Azure Functions
  3. Web Jobs

In Azure Logic Apps, you can build a workflow to migrate the date via "recurrence" trigger.

In Azure Functions you can use Timer Trigger and write your own logic using Azure Service Bus SDK / REST API. You can find more information about Timer Trigger here for C# script, but you can also use JS, F#, etc. In case you are going with Azure Function, if the scheduled time is every 5 minutes, the function.json will be coded like below

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

The code for the function will be something like below

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
}

I am using the .NET SDK for Azure Service Bus, you can find the reference here. If you are new to Azure Functions, the C# scripting function works slightly in a different way. The approach of referencing a dll is different. You can find it here.

When it comes to Azure Web Jobs, its running as a part of Azure Web apps. For Azure Web Job, you can write a webjob using a console application template as well. You can use the same Azure Service Bus SDK mentioned above for the development of the Web Job as well. Find the documentatio of Azure Web Jobs here.

Isham Mohamed
  • 2,629
  • 1
  • 14
  • 27
  • Thanks Isham for your time, but my question is less about how to code an Azure Function (I am ok with this) but more about scheduling a recurring message with MassTransit running on Azure Service Bus. Previously I would have used Quartz Scheduler with MT on RabbitMq but we are migrating to Azure and we need the same functionality. Kicking off a function which is doing all the legwork of talking to MT rather than try and send an MT message from Azure Scheduler. This approach seems to be working well for me so far. – robs Apr 01 '19 at 12:12
  • My only concern is Azure Scheduler is being retired. Have you tried Logic Apps? But with Logic apps there is a pricing in place and with Functions and Webjobs you can use it for free upto certain extent. – Isham Mohamed Apr 02 '19 at 02:25