Mass transit with quartz / planning. Are there any implementation examples?

I searched high and low for an implementation example or blog post about how to use integration with quasi-mass ( https://github.com/MassTransit/MassTransit-Quartz ).

At the moment, I only have to think about the unit tests that come with the code base, and I have not achieved much success.

Are there any examples or good blog posts to help me get started with Mass Transit and Quartz Scheduling?

+6
source share
1 answer

In this example, you can save the MassTransit mass schedule to an SQL database. Out of the box, MassTransit is only stored in memory without any configuration changes.

First of all, you need to make minor changes to the app / web.config file to include the following 2 blocks:

<configSections> <section name="quartz" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" /> 

  <quartz> <add key="quartz.scheduler.instanceName" value="MassTransit-Quartz" /> <add key="quartz.scheduler.instanceId" value="AUTO" /> <add key="quartz.threadPool.type" value="Quartz.Simpl.SimpleThreadPool, Quartz" /> <add key="quartz.threadPool.threadCount" value="4" /> <add key="quartz.threadPool.threadPriority" value="2" /> <add key="quartz.jobStore.misfireThreshold" value="60000" /> <add key="quartz.jobStore.type" value="Quartz.Impl.AdoJobStore.JobStoreTX, Quartz" /> <add key="quartz.jobStore.useProperties" value="false" /> <add key="quartz.jobStore.driverDelegateType" value="Quartz.Impl.AdoJobStore.SqlServerDelegate, Quartz" /> <add key="quartz.jobStore.clustered" value="true" /> <add key="quartz.jobStore.tablePrefix" value="QRTZ_" /> <add key="quartz.jobStore.dataSource" value="quartzDS" /> <add key="quartz.dataSource.quartzDS.connectionString" value="Server=(local);Database=Quartz;Integrated Security=SSPI" /> <add key="quartz.dataSource.quartzDS.provider" value="SqlServer-20" /> 

Then in local SQL, create a new database named "Quartz", load the source quartz.net and find the database script

"tables_sqlServer.sql"

run this against the local Quartz database to create the schema. Now that you have everything you need to save the scheduled messages in the database, you need to subscribe to these two consumers from the Mass Quintz MassTransit integration library:

 var scheduler = CreateScheduler(); sb.SubscribeConsumer(() => new ScheduleMessageConsumer(scheduler)); sb.SubscribeConsumer(() => new CancelScheduledMessageConsumer(scheduler)); 

If the scheduler is IScheduler:

 static IScheduler CreateScheduler() { ISchedulerFactory schedulerFactory = new StdSchedulerFactory(); return schedulerFactory.GetScheduler(); } 

and sb is your service server like IServiceBus.

Finally, in your code call:

  Bus.ScheduleMessage(SchedulePeriodInSecondsFromNow, MessageToSchedule); 

And there is a consumer for the type "MessageToSchedule". If you open the database and query the QRTZ_TRIGGERS table, you will see the jobs that appear there, and in QRTZ_JOB_DETAILS.

Hope this helps!

+6
source

Source: https://habr.com/ru/post/959249/


All Articles