我想将Masstransit调度API用于多租户应用程序。我需要为每个租户发送重复的消息。
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;
}
}
问题是调度程序使用类名“MyScheduler”作为作业名称,并且不能使用MyScheduler发送两个重复的消息。有没有办法用Masstransit调度API实现多租户?
答案 0 :(得分:1)
将构造函数中的ScheduleId
和/或ScheduleGroup
(对于您的MySchedule
类)更改为特定于租户,并且它将更改Quartz使用的标识符。
public class MySchedule : DefaultRecurringSchedule
{
public MySchedule(string cronExpression, string description, string tenantId)
{
CronExpression = cronExpression;
Description = description;
ScheduleId = "MyScheduleForTenant" + tenantId;
}
}