Quartz integration tutorial

101 views
Skip to first unread message

Mehdin Hodzic

unread,
Mar 29, 2018, 2:59:31 AM3/29/18
to masstransit-discuss
Hi,

I'm new to MT (and Quartz) and trying to implement scheduled messaging by reading CQRS Journey tutorials.
I need a way to schedule command to trigger in 15 minutes, but I cannot find any tutorial how to setup Quartz.
It only works when I use in memory scheduler, but I want to know how to make reliable solution.

Below is my minimal code sample and I want to know where I can find more information how to setup Quartz (storage and configuration) for .NET Core 2.0 application

using MassTransit;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MTSchTest
{
    class Program
    {
        static void Main(string[] args)
        {
            var busControl = Bus.Factory.CreateUsingRabbitMq(cfg =>
            {
                var host = cfg.Host(new Uri("rabbitmq://localhost/"), h =>
                {
                    h.Username("guest");
                    h.Password("guest");
                });

                cfg.UseMessageScheduler(new Uri("rabbitmq://localhost/quartz")); // This doesn't work, is there any tutorial how to configure, e.g. SQLServer DB storage
                //cfg.UseInMemoryScheduler(); // This only works

                cfg.ReceiveEndpoint(host, "messages", ep =>
                {
                    ep.Handler<SampleMessage>(context =>
                    {
                        Console.WriteLine($"Message received...{context.Message.Name}");
                        return Task.CompletedTask;                        
                    });
                });                
            });

            busControl.Start();

            var sendEndpoint = busControl.GetSendEndpoint(new Uri("rabbitmq://localhost/quartz")).Result;
            sendEndpoint.ScheduleSend(new Uri("rabbitmq://localhost/messages"), DateTime.Now.AddSeconds(5), new SampleMessage() { Name = "Test"});           

            Console.ReadLine();
        }
    }

    public class SampleMessage
    {
        public string Name { get; set; }
    }
}

Mehdin Hodzic

unread,
Mar 29, 2018, 5:10:22 AM3/29/18
to masstransit-discuss
I found it and here is what I have done, just in case that someone needs it and doesn't have time to read documentation:

I compiled and started MassTransit.QuartzService project from MassTransit solution (default quartz endpoint is masstransit_quartz_scheduler, check app.config file).
I also updated it in order to use SqlServer instead of provided SQLite database (app.config file -> there are sections for SQLite and SQL Server).
SQL Server DB script is available in Quartz.NET downloadable from https://github.com/quartznet/quartznet/releases/download/v3.0.4/Quartz.NET-3.0.4.zip

I also needed to change provider name from SqlServer-20 to SqlServer (<add key="quartz.dataSource.quartzDS.provider" value="SqlServer" /> line).
Reply all
Reply to author
Forward
0 new messages