Reputation: 31
I would like use Masstransit scheduling API for multi tenant application. I need to send recurring messages per tenant.
var schedule1 = new MySchedule("1 * * * * ?", "Tenant 1");
var schedule2 = new MySchedule("6 * * * * ?", "Tenant 2");
endPoint.Result.ScheduleRecurringSend(sendToUri, schedule1, new OrderCommand
{
Id = Guid.NewGuid().ToString(),
Name = "Tenant 1"
});
endPoint.Result.ScheduleRecurringSend(sendToUri, schedule2, new OrderCommand
{
Id = Guid.NewGuid().ToString(),
Name = "Tenant 2"
});
public class MySchedule : DefaultRecurringSchedule
{
public MySchedule(string cronExpression, string description)
{
CronExpression = cronExpression;
Description = description;
}
}
The problem is that the scheduler uses class name "MyScheduler" as a job name and can't send two recurring messages using MyScheduler. Is there a way to implement multitenancy with Masstransit scheduling API?
Upvotes: 1
Views: 449
Reputation: 33542
Change the ScheduleId
and/or ScheduleGroup
in your constructor (for your MySchedule
class) to be tenant-specific, and it will change the identifier used by Quartz.
public class MySchedule : DefaultRecurringSchedule
{
public MySchedule(string cronExpression, string description, string tenantId)
{
CronExpression = cronExpression;
Description = description;
ScheduleId = "MyScheduleForTenant" + tenantId;
}
}
Upvotes: 1